Arshad Rehmani
Arshad Rehmani

Reputation: 2185

JQuery: Find all ids starting with any one of the specified Strings

I understand that I can use below selector to select a div starting with one string.

$('[id^="content_"]')

Find All Ids starting with a String

I have Divs that starts with Strings "content_" or "list_". How do I select all divs on my document that starts with one of above 2 strings? Something like below that should work,

$('[id^="content_"] OR [id^="content_"]')

Upvotes: 1

Views: 1491

Answers (2)

Shoaib Chikate
Shoaib Chikate

Reputation: 8975

Use comma to have multiple selectors. It will consider both

$('[id^=content_],[id^=list_]').each(function(){

   alert($(this).text());
  
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="anchor">Shoaib</div>
<div id="content_anchor">Sajeed</div>
<div id="list_anchor">Chikate</div>

Upvotes: 1

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

You can use comma separated list of jquery selectors

$('[id^="content_"],[id^="list_"]')

Upvotes: 4

Related Questions