MCPcopy Create free account
hub / github.com/JsAaron/jQuery / dataAttr

Function dataAttr

2.1.1/src/data.js:22–49  ·  view source on GitHub ↗
( elem, key, data )

Source from the content-addressed store, hash-verified

20 rmultiDash = /([A-Z])/g;
21
22function dataAttr( elem, key, data ) {
23 var name;
24
25 // If nothing was found internally, try to fetch any
26 // data from the HTML5 data-* attribute
27 if ( data === undefined && elem.nodeType === 1 ) {
28 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
29 data = elem.getAttribute( name );
30
31 if ( typeof data === "string" ) {
32 try {
33 data = data === "true" ? true :
34 data === "false" ? false :
35 data === "null" ? null :
36 // Only convert to a number if it doesn't change the string
37 +data + "" === data ? +data :
38 rbrace.test( data ) ? jQuery.parseJSON( data ) :
39 data;
40 } catch( e ) {}
41
42 // Make sure we set the data so it isn't changed later
43 data_user.set( elem, key, data );
44 } else {
45 data = undefined;
46 }
47 }
48 return data;
49}
50
51jQuery.extend({
52 hasData: function( elem ) {

Callers 1

data.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected