Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can .ready() event be used on other tags than document

Tags:

jquery

Can .ready() event be used on other tags than document? example:

$("#test").ready(function() {
  $("#test").click(function () {
    alert("test");
  });
});
like image 752
Ghooti Farangi Avatar asked Apr 03 '11 12:04

Ghooti Farangi


People also ask

Do you need to use document ready?

No, it is not necessary. You can either put the script tag right before the body closing tag or if you are supporting IE9+ you can use native JS.

What is the equivalent of document ready in JavaScript?

jQuery $(document). ready() Equivalent in JavaScript This event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

Which of the following event fires first document ready or document load?

The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

What is the difference between the $( document .ready and window onload events?

The key difference between $(document). ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc.


1 Answers

Quoting .ready()'s documentation's page :

The .ready() method can only be called on a jQuery object matching the current document


The selector can be omitted, but it won't change a thing : it'll still work on the document.

like image 175
Pascal MARTIN Avatar answered Nov 02 '22 04:11

Pascal MARTIN