easierbycode
2/10/2012 - 7:51 AM

jQuery Private Data Should Stay Private

jQuery Private Data Should Stay Private

$( 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" ) );
  
});
<!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>