Asked 3 years ago
28 May 2021
Views 569
samir

samir posted

how document ready work in jquery ?

what is document ready in jquery ?
how document ready in jquery ?
how to use document ready in jquery ?
jaydeep

jaydeep
answered Nov 30 '-1 00:00

in jQuery , document ready is good function to avoid problem where apply code on not loaded dom element

document.ready run enclosed javascript or jquery code after dom rendering

$( document ).ready(function() {
   alert( "hello" );
});


in above code , it will display alert with message "hello" after HTML page dom ready

short hand of document.ready :


$(function() {
    alert( "hello" );
});

above code also work same as document.ready , $(function() { is short hand code for $( document ).ready(function() {
so above code will show alert box after page load completion and HTML DOM ready
jqueryLearner

jqueryLearner
answered Aug 19 '21 00:00


$(document).ready(function() {
  console.log('hi');
});

console.log('hi'); will be executed when HTML-Document is loaded and DOM is ready


Post Answer