tags:

views:

25

answers:

1

Using jquery, how can I select all the DIVs in my document with ID names containing specific text?

I want to select all the elements that contain 'parent', the problem is the string parent might be in the middle of the string.

I've been trying to use:

var allcontent_collection = $('div[id^=.*parent.*]')

It is not working. Should it or am I completely wrong in my approach?

+3  A: 

You can do it using the attribute-contains (*=) selector instead, like this:

var allcontent_collection = $("div[id*='parent']")
Nick Craver
I don't think you need the single quotes there, but I'm not positive.
hookedonwinter
@hookedonwinter - They are inddeed optional for *this* example, just giving a more general approach that works for others as well :)
Nick Craver