document.addEventListener("DOMContentLoaded", function() {
// code
});
// A document ready block with JQery.
$( document ).ready(function() {
// we ready for fire action with JQery.
});
// A document ready block with javascript.
document.addEventListener("DOMContentLoaded", function(event) {
// we ready for fire action with javascript.
});
Two syntaxes can be used for this:
$( document ).ready(function() {
console.log( "ready!" );
});
Or the shorthand version:
$(function() {
console.log( "ready!" );
});
// A $( document ).ready() block.
$( document ).ready(function() {
console.log( "ready!" );
});
document.addEventListener("DOMContentLoaded", function(event) {
//we ready baby
});
window.onload = function() {
};
1
2
3
4
// Shorthand for $( document ).ready()
$(function() {
console.log( "ready!" );
});
document.addEventListener("DOMContentLoaded", fn);
$(document).ready(function () {
//write your code here
});
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}