I’m new to Jquery. See an example at http://w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_p. Here, clicking ‘Click Me’ button the text change. My question is why the following code need to wrapped under $(document).ready(function(){ )}. Otherwise, it doesn’t work.
Thanks so much for all your help and really appreciate.
$("button").click(function(){
$("p").hide();
});
Yes, if you didn’t wrap this code in the
$(document).ready()handler, the objects wouldn’t exist because the DOM isn’t loaded.This is a simple test to ensure that the DOM is ready, before invoking methods on its elements.