.width() giving error $(…)[0].width is not a function?

前端 未结 4 993
生来不讨喜
生来不讨喜 2021-01-19 05:01

I have a table, and I\'m trying to find the width of each td in the table. I\'ve tried all kinds of variations of: $(\"td\")[0].width(), but none of them work,

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 05:40

    $("td")[0] is a DOM element not a jquery object. Simply wrap it as jquery $($("td")[0]).width()

    You need to get width of each td so you could use something like

    $.each('td', function() {
        var currentTDWidth = $(this).width(); // more code here
    });
    

提交回复
热议问题