Skip to content

Instantly share code, notes, and snippets.

@imparvez
Created November 13, 2017 20:09
Show Gist options
  • Save imparvez/463cfc9ab23373c3ea83650ee60a729d to your computer and use it in GitHub Desktop.
Save imparvez/463cfc9ab23373c3ea83650ee60a729d to your computer and use it in GitHub Desktop.
The DOM Ready Event: The first step to manipulating the DOM is subscribing to the DOM Ready event. This is not only a matter of convention – the event is fired only when all page elements are present and accessible, so your jQuery selectors actually return anything. But do you know that there is a neat way to subscribe to the ready event that wo…
/* Chapter No: 1 DOM Manipulation */
// 1. DOM Ready Event: Subscribing the DOM event.
// 1. With Jquery
$(document).ready(function(){
alert('First Method');
});
// 2. Shorter Jquery Version
$(function(){
alert('Second Method')
});
// 3. Without Jquery, doesn't work with older IEs.
document.addEventListener('DOMContentLoaded', function () {
alert( 'document was not ready, place code here' );
});
// 4. Works everywhere
r(function(){
alert('DOM Ready!');
});
function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment