jQuery and CSS ‘Wildcard’ element selection

UPDATE 08-26-2013
No need for any quotes on either unless it is a number example [class$=’23’], CSS and jQuery syntax is the same.

Quick Start Guide:
CSS and jQuery ‘WIldcard’ Syntax(‘type’ = class or id):
Starts with: [type^=keyword]  Ends with: [type$=keyword] contains: [type*=keyword]

 Try it yourself on CodePen!

This is a really awesome trick I found that you can do, comes in handy for dynamically incremented IDs :

To get all the elements starting with “awesomeSauce” you should use:

$("[id^=awesomeSauce]")

To get those that end with “awesomeSauce”

$("[id$=awesomeSauce]")

Also words for classes that start start with “awesomeSauce”  ex: “awesomeSauce123”

$('[class^=awesomeSauce]')

Or if you have multiple classes on an object, like ” best awesomeSauce123″ or you want to find an id or class that contains the keyword.

$('[class*=awesomeSauce]')

Giving Credit where credit is due:

http://stackoverflow.com/questions/5376431/wildcards-in-jquery-selectors

Leave a Reply