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

前端 未结 6 1065
误落风尘
误落风尘 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:29

    // ...
    $('.box', boxOutput).each(function(i) {
       //boxWidth += $(this).width(); /* this is where sometimes width returns 0 */
       boxWidth += this..getBoundingClientRect().width;
    });
    //...
    

提交回复
热议问题