I need to be able to get the width of elements from an array
HTML
<div id="container">
<ul>
<li id="one">--------</li><br />
<li id="two">----------------</li><br />
<li id="three">-------</li><br />
</ul>
</div>
JS
I know i can access the individual width's like this
$('#one').width();
But in an array
var $array = $("#container li");
How do i access a specific width of the element by its index
e.g
$array[2].width(); //which causes error
Example http://jsfiddle.net/8zvkn/
Use eq :
$('#container li').eq(i)
You can use .eq
function like below,
$array.eq(2).width()
DEMO: http://jsfiddle.net/8zvkn/2/
$array[2]
- returns DOM element but what you need is the jQuery object which has the .width
function.
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