Reputation: 2185
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
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
Reputation: 28513
You can use comma separated list of jquery selectors
$('[id^="content_"],[id^="list_"]')
Upvotes: 4