MCPcopy Create free account
hub / github.com/unconed/TermKit / dataAttr

Function dataAttr

HTML/jquery.js:1661–1688  ·  view source on GitHub ↗
( elem, key, data )

Source from the content-addressed store, hash-verified

1659});
1660
1661function dataAttr( elem, key, data ) {
1662 // If nothing was found internally, try to fetch any
1663 // data from the HTML5 data-* attribute
1664 if ( data === undefined && elem.nodeType === 1 ) {
1665 var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
1666
1667 data = elem.getAttribute( name );
1668
1669 if ( typeof data === "string" ) {
1670 try {
1671 data = data === "true" ? true :
1672 data === "false" ? false :
1673 data === "null" ? null :
1674 !jQuery.isNaN( data ) ? parseFloat( data ) :
1675 rbrace.test( data ) ? jQuery.parseJSON( data ) :
1676 data;
1677 } catch( e ) {}
1678
1679 // Make sure we set the data so it isn't changed later
1680 jQuery.data( elem, key, data );
1681
1682 } else {
1683 data = undefined;
1684 }
1685 }
1686
1687 return data;
1688}
1689
1690// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
1691// property to be considered empty objects; this property always exists in

Callers 1

jquery.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected