Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

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, getting an error of: "Uncaught TypeError: $(...)[0].width is not a function" everytime.

I'm importing jQuery first, before my other JS files, (https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js), and I'm using .width() not .width.

Any ideas?

like image 564
andofcourse Avatar asked Dec 24 '22 10:12

andofcourse


1 Answers

$("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
});
like image 116
Alexandru Chichinete Avatar answered Dec 27 '22 02:12

Alexandru Chichinete