Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let the javascript executed just when dom and css is ready but not image

I want execute some javascript just when the dom and css is ready, but I don't care about the image(I'm tend to lazyload the image)

I know how to detect the dom ready status, but how to detect the css is ready?

like image 610
hh54188 Avatar asked Dec 28 '12 03:12

hh54188


People also ask

Does JavaScript run before CSS?

When it comes to ordering your CSS and JavaScript, you want your CSS to come first. The reason is that the rendering thread has all the style information it needs to render the page. If the JavaScript includes come first, the JavaScript engine has to parse it all before continuing on to the next set of resources.

Can JavaScript run before page load?

You can run javascript code at any time. AFAIK it is executed at the moment the browser reaches the <script> tag where it is in. But you cannot access elements that are not loaded yet.

What is the difference between document ready () and window onload ()?

ready() is a jQuery event which occurs when the HTML document has been fully loaded, while the window. onload event occurs later, when everything including images on the page loaded. Also window. onload is a pure javascript event in the DOM, while the $(document).


Video Answer


1 Answers

You should be using the document.ready event. window.onLoad fires when all the images and others are fully loaded.

Source: window.onload vs $(document).ready()

like image 78
janith Avatar answered Oct 14 '22 09:10

janith