Reputation: 305
I have my div like this
<div id="gallery-1"></div>
<div id="gallery-2"></div>
<div id="gallery-3"></div>
<div id="gallery-4"></div>
<div id="gallery-5"></div>
How can I select them in one jquery selector? like
jQuery("#gallery-*").something();
Any Ideas?
Upvotes: 0
Views: 66
Reputation: 1718
jQuery("div")
or change id
to class
inside your HTML and specify the following jQuery code: jQuery(".gallery")
.
You can also use more advanced selector syntax like jQuery("div[id='^gallery']")
, as Rajaprabhu suggested.
Upvotes: 0
Reputation: 85545
You can use start with selector
jQuery('div[id^=gallery]').something();
Upvotes: 0
Reputation: 67207
Try to use attribute starts with selector
at this context,
jQuery("[id^='gallery-']").something();
Or the best way would be using a common class,
HTML:
<div id="gallery-1" class='test'></div>
<div id="gallery-2" class='test'></div>
<div id="gallery-3" class='test'></div>
<div id="gallery-4" class='test'></div>
<div id="gallery-5" class='test'></div>
JS:
jQuery(".test").something();
Upvotes: 6