Can .ready() event be used on other tags than document? example:
$("#test").ready(function() {
$("#test").click(function () {
alert("test");
});
});
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With