I'm new to jQuery and I'm still learning so I apologise if this is a silly question!
Basically I'm trying to get the number of elements in my page with a certain class. My searching tells me I need to use .length but it's not working for some reason.
Any ideas at a quick glance at what may be causing the issue?
var item = $('.item')
var itemWidth = item.width();
var numberItems = item.length();
console.log(numberItems);
Thanks!!
It's just item.length - the length property is a number, and you're trying to call it as a function, so you get that error.
Now width is a function; you may be looking for .height(). The length property tells you how many elements matched the selector (more generally, the size of the jQuery collection). DOM elements are measured by width and height (.width() and .height(), along with .innerWidth(), .innerHeight(), .outerWidth(), and .outerHeight()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With