MCPcopy Index your code
hub / github.com/JsAaron/jQuery / dataAttr

Function dataAttr

1.6.1/src/data.js:283–310  ·  view source on GitHub ↗
( elem, key, data )

Source from the content-addressed store, hash-verified

281});
282
283function dataAttr( elem, key, data ) {
284 // If nothing was found internally, try to fetch any
285 // data from the HTML5 data-* attribute
286 if ( data === undefined && elem.nodeType === 1 ) {
287 var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
288
289 data = elem.getAttribute( name );
290
291 if ( typeof data === "string" ) {
292 try {
293 data = data === "true" ? true :
294 data === "false" ? false :
295 data === "null" ? null :
296 !jQuery.isNaN( data ) ? parseFloat( data ) :
297 rbrace.test( data ) ? jQuery.parseJSON( data ) :
298 data;
299 } catch( e ) {}
300
301 // Make sure we set the data so it isn't changed later
302 jQuery.data( elem, key, data );
303
304 } else {
305 data = undefined;
306 }
307 }
308
309 return data;
310}
311
312// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
313// property to be considered empty objects; this property always exists in

Callers 1

data.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected