Reputation: 5280
I would like to access a selector in my array:
<ul>
<li class="elem">A</li>
<li class="elem">B</li>
<li class="elem">C</li>
</ul>
var $elems = $('li.elem');
console.log($elems[1].text()); /* jQuery method call */
I know there is the get()
method, but it seems to be an implementation to se []
operator.
So what is the best way to access an item on a jQuery array?
Should we do something like $($elems[1]).text()
?
Upvotes: 0
Views: 68
Reputation: 4144
You could try followings ways
// jQuery Method call
console.log( $($elems[1] ).text() );
console.log( $elems.filter(':eq(1)').text() );
console.log( $elems.eq(1).text() );
//native method
console.log( $elems[1].innerHTML );
All prints same results
Upvotes: 0