Skip to content

Instantly share code, notes, and snippets.

@ivolivares
Forked from elijahmanor/fiddle.html
Created December 14, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivolivares/7250dd8c8e009ca294bc to your computer and use it in GitHub Desktop.
Save ivolivares/7250dd8c8e009ca294bc to your computer and use it in GitHub Desktop.
jQuery Private Data Should Stay Private
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<p id="hello">Hello World</p>
</body>
</html>
$( function() {
var $hello = $( "#hello" ).click( function() {
alert( "hello world" );
});
// does NOT return object that includes the events property
console.log( $hello.data() );
// does return events object
console.log( $hello.data( "events" ) );
// does return object that includes the events property
console.log( $._data( $hello[ 0 ] ) );
// does return evetns object
console.log( $._data( $hello[ 0 ], "events" ) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment