Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector all ids that are integer

How do I select all ids which are the integers.

for example

<div id="1"></div>
<div id="2"></div>
<div id="3"></div>

somdething [id^="integer"]?

I know how to select ids that has similar name starting:

[id^="similar_"]
like image 464
SamotnyPocitac Avatar asked Dec 01 '22 16:12

SamotnyPocitac


1 Answers

You can use filter(). The equivalent of [id^=integer] would be :

$('div').filter(function(){
    return this.id.match(/^\d/);
})

Only integer would be :

$('div').filter(function(){
    return this.id.match(/^\d+$/);
})
like image 191
Karl-André Gagnon Avatar answered Dec 10 '22 11:12

Karl-André Gagnon