load(function(){ // ...}) @undefined, this is almost the same as $(document). ready(function(){ ... }) . load() will wait until the graphics are also loaded.
Answer: Use the DOMContentLoaded Event You can utilize the JavaScript Window's DOMContentLoaded event to construct $(document). ready() equivalent without jQuery.
$( document ). ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ). ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
The equivalent to $() or jQuery() in JavaScript is querySelector() or querySelectorAll() , which, just like with jQuery, you can call with a CSS selector.
Do stuff when DOM is ready.
$(function(){
// DOM Ready - do your stuff
});
Try this:
document.addEventListener('DOMContentLoaded', function() {
// ...
});
Works in modern browers and IE9+
You could use the standard js onload function to run if that's what your'e missing:
window.onload = function() {};
Do note that this might give you issues with libraries - I haven't investigated that.
I believe using the script defer
tag is the best solution. For example,
<script src="demo_defer.js" defer></script>
More information at W3 Schools.
best ways is to use like this:
jQuery.noConflict();
(function($) {
$(function() {
// by passing the $ you can code using the $ alias for jQuery
alert('Page: ' + $('title').html() + ' dom loaded!');
});
})(jQuery);
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