MCPcopy Create free account
hub / github.com/frank-lam/fullstack-tutorial / dataAttr

Function dataAttr

notes/docsify/unpkg/gotop/jquery-2.1.0.js:3675–3702  ·  view source on GitHub ↗
( elem, key, data )

Source from the content-addressed store, hash-verified

3673 rmultiDash = /([A-Z])/g;
3674
3675function dataAttr( elem, key, data ) {
3676 var name;
3677
3678 // If nothing was found internally, try to fetch any
3679 // data from the HTML5 data-* attribute
3680 if ( data === undefined && elem.nodeType === 1 ) {
3681 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
3682 data = elem.getAttribute( name );
3683
3684 if ( typeof data === "string" ) {
3685 try {
3686 data = data === "true" ? true :
3687 data === "false" ? false :
3688 data === "null" ? null :
3689 // Only convert to a number if it doesn't change the string
3690 +data + "" === data ? +data :
3691 rbrace.test( data ) ? jQuery.parseJSON( data ) :
3692 data;
3693 } catch( e ) {}
3694
3695 // Make sure we set the data so it isn't changed later
3696 data_user.set( elem, key, data );
3697 } else {
3698 data = undefined;
3699 }
3700 }
3701 return data;
3702}
3703
3704jQuery.extend({
3705 hasData: function( elem ) {

Callers 1

jquery-2.1.0.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected