jQuery: Why does .width() sometimes return 0 after inserting elements with .html()?

前端 未结 6 1077
误落风尘
误落风尘 2021-02-07 00:57

I am getting some html and inserting it with .html(), after which I am trying to get the width of one of newly inserted elements with .width() (which h

6条回答
  •  攒了一身酷
    2021-02-07 01:10

    We found out that document.ready was not good enough so 300ms worked well:

        setTimeout(function() {
            resizeHeightOfMyDiv();
    
            $(window).on("resize", function() {
                resizeHeightOfMyDiv();
            });
         }, 300);
    

提交回复
热议问题