Do something AFTER the page has loaded completely

前端 未结 8 682
日久生厌
日久生厌 2020-12-08 20:41

I\'m using some embed codes that insert HTML to the page dynamically and since I have to modify that dynamically inserted HTML, I want a jquery function to wait until the pa

相关标签:
8条回答
  • 2020-12-08 21:10

    Try this:

    $(document).ready(function () {
        if ( $('#abc')[0] ) { 
          alert("yes");
        }
    });
    
    0 讨论(0)
  • 2020-12-08 21:10
    $(window).load(function () { ... }
    

    can be enough but otherwise your embeded code (what ever that can be) might provide some callback functionality that you can make use of.

    delay() should only be used to delay animations.

    0 讨论(0)
  • 2020-12-08 21:11

    The load() method was deprecated in jQuery version 1.8 and removed in version 3.0. So you have to use -

    $(window).on('load', function() {
     // code here
    });
    
    0 讨论(0)
  • 2020-12-08 21:27

    That is the purpose of jQuery's .ready() event:

    $(document).ready(function() {
        if ( $('#abc').length ) //If checking if the element exists, use .length
            alert("yes");
    });
    

    Description: Specify a function to execute when the DOM is fully loaded.

    0 讨论(0)
  • 2020-12-08 21:32

    Generally, to handle my JQuery before or after page loads, will use:

    jQuery(function($){
        // use jQuery code here with $ formatting
        // executes BEFORE page finishes loading
    });
    
    jQuery(document).ready(function($){
        // use jQuery code here with $ formatting
        // executes AFTER page finishes loading
    });
    
    0 讨论(0)
  • 2020-12-08 21:34

    Make sue you bind the event with dom load so it's there when trigger called. This is how you do it. Hope this helps someone someday

    $(window).bind("load", function() { 
       //enter code here
       $("#dropdow-id").trigger('change');
    });`
    
    0 讨论(0)
提交回复
热议问题