It's a common belief that ID selectors are the fastest, but this comes with a big caveat: IDs are fastest CSS selector only if they're the key selector.
The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
ID and Element selector are the fastest selectors in jQuery.
Normally you would select IDs using the ID selector #
, but for more complex matches you can use the attribute-starts-with selector (as a jQuery selector, or as a CSS3 selector):
div[id^="player_"]
If you are able to modify that HTML, however, you should add a class to your player div
s then target that class. You'll lose the additional specificity offered by ID selectors anyway, as attribute selectors share the same specificity as class selectors. Plus, just using a class makes things much simpler.
try this:
$('div[id^="player_"]')
You can use meta characters like *
(http://api.jquery.com/category/selectors/).
So I think you just can use $('#player_*')
.
In your case you could also try the "Attribute starts with" selector:
http://api.jquery.com/attribute-starts-with-selector/: $('div[id^="player_"]')
$('div[id ^= "player_"]');
This worked for me..select all Div starts with "players_" keyword and display it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With