Check if a given DOM element is ready

后端 未结 5 766
不知归路
不知归路 2020-12-29 04:28

Is there a way of checking if the HTML DOM element/s for a given selector/element are ready yet using jQuery or JavaScript?

Looking at the jQuery api for the ready

5条回答
  •  甜味超标
    2020-12-29 05:24

    Yes, it is possible: and while it's not native, it is pretty easy to impliment. Just trigger a custom event after the node you're looking for is loaded into the DOM.

    Note: I'm writing this in jQuery, which means you have to include jQuery early in the load process, which is a no-no performance wise. That being said, if you already have jQuery high up in your document or if DOM construction is taking a hella long time for you, this might be worthwhile. Otherwise, you're free to write this in vanilla JS to skip the $ dependency.

    
    Incremental DOM Readyness Test
        
        
        
        
        

提交回复
热议问题