Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select class jquery

I have a class called formStyle which occurs several times in my webpage. Is it possible to select let's say first and third (with jquery) if they are five

like image 378
Nick Avatar asked Dec 03 '22 02:12

Nick


2 Answers

You can use jQuery's :eq()-selector, but it is easier (and probably faster, due to native selectors) to select all of them and pick the ones you need afterwards:

var elements = $('.formStyle');
elements.eq(0) // first
elements.eq(2) // third
like image 197
jwueller Avatar answered Dec 14 '22 14:12

jwueller


yep, like this

$('.formStyle:eq(0), .formStyle:eq(2)')
like image 33
Teneff Avatar answered Dec 14 '22 15:12

Teneff