Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count elements that the id begins with a certain string [duplicate]

Possible Duplicate:
jQuery Return elements where ID begins with a certain string

Ok, let's say I have the following elements:

<select id="state_id" value="20">test1</select>
<select id="state_id1" value="21">test2</select>
<select id="state_id2" value="22">test3</select>

How can I get the length() of the select tags that the id begins with state_id in this case?

I have tried: $("^#state_id").length(); but no success.

Any hint?

like image 900
Kleber S. Avatar asked Dec 03 '22 02:12

Kleber S.


1 Answers

Try this...

$('[id^=state_]').length
like image 162
Mac Attack Avatar answered Feb 16 '23 04:02

Mac Attack