Is it possible to select multiple elements using an array selector?
If so, what is the best way to do it? In my project, I need to use only array selectors.
This is my sample code:
<ul>
<li>1<li>
<li>2<li>
<li>3<li>
<li>4<li>
<li>5<li>
</ul>
<a href="#">select</a>
$('a').click(function(){
var element = $('ul').find('li')[0]; // Instead is it possible $('ul').find('li')[0,3,4]? I know we can select finding each alone. But is there any shortcut?
$(element).css({border:'1px solid red'});
})
This would give desired result. Simply filter by index() and use inArray().
Basicly all the
<li>are run through the each() and then I loop to check if given .index() is in given array. If they don’t exist ( $.inArray() == -1 ) then I do a return; to skip execution.