Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: get all children whose ID contains part of string

Tags:

html

jquery

I have a set of links:

<div id="parent">
   <a id="UserFirst" href="#"></a>
   <a id="UserSecond" href="#"></a>
   <a id="UserThird" href="#"></a>
</div>

I need a quick way of getting (for example) all the a children of #parent, whose ID contains the letter i.

How can I do it?

like image 575
ojek Avatar asked Sep 15 '13 19:09

ojek


1 Answers

Use jquery contains selector:

$("#parent").find("a[id*='i']").each(function(){
//do something here
});

DEMO FIDDLE

like image 114
Kiran Avatar answered Nov 03 '22 01:11

Kiran