If i have a few classes named something similar is there a way to grab them all in one shot
#instance1
#instance2
#instance3
#instance4
("#instance").click(function()
//GRAB ALL OF THEM
If i have a few classes named something similar is there a way to grab them all in one shot
#instance1
#instance2
#instance3
#instance4
("#instance").click(function()
//GRAB ALL OF THEM
Why don't you just assign class = "instance" to all of them and select them using $('.instance')?
Those are IDs, but you can do something similar to:
$("[id^='instance']").click(...)
That's a bit expensive though - it helps if you can specify either a) the type of element or b) a general position in the DOM, such as:
$("#someContentDiv span[id^='instance']").click(...)
The [id^='...'] selector basically means "find an element whose ID starts with this string, similar to id$= (ID ends with this string), etc.
You can find a comprehensive list on the jQuery Docs page here.
The attribute starts-with selector ('^=) will work for your IDs, like this:
$("[id^=instance]").click(function() {
//do stuff
});
However, consider giving your elements a common class, for instance (I crack myself up) .instance, and use that selector:
$(".instance").click(function() {
//do stuff
});