Skip to content

Instantly share code, notes, and snippets.

@caulfield
Created January 13, 2017 14:07
Show Gist options
  • Save caulfield/fd17c67879ada1d1597c942e380285f8 to your computer and use it in GitHub Desktop.
Save caulfield/fd17c67879ada1d1597c942e380285f8 to your computer and use it in GitHub Desktop.
DOM events
<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script
src="index.js"></script>
</head>
<body class="wrapper">
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
console.log('before document ready')
console.debug('is body', $('body').length == 1)
console.debug('is nested', $('h1').length == 1)
console.debug('is document', $(document).length == 1)
console.debug('is document.body', $(document.body).length == 1)
$('body').mouseenter(function() {
console.log('hover attached on body BEFORE document ready');
});
$(document).ready(function() {
console.log('after document ready')
console.debug('is body', $('body').length == 1)
console.debug('is nested', $('h1').length == 1)
console.debug('is document', $(document).length == 1)
console.debug('is document.body', $(document.body).length == 1)
$('body').mouseenter(function() {
console.log('hover attached on body AFTER document ready');
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment