views:

25

answers:

2

Need help writing a regular expression to match any class containing the phrase block-container

I've come up with this: '[class^=block-container]' but I need help writing the wild cards around the phrase block-container.

Examples i need to match:

 nav-block-container-left
 block-container-whitebox
 right-block-container
+1  A: 
$("[class*=block-container]")
Mark Ursino
That worked, does the * tell it to find any string containing the words block-container? Explaining why ^ only included it if block-container was at the beginning of the string. If that is correct it makes a lot more sense now. Thanks
JMC
Yes, the *= is the "contains" selector. The ^= is the "starts with" selector. They're all listed here: http://api.jquery.com/category/selectors/
Mark Ursino
Yes. See http://api.jquery.com/category/selectors/ . *= is "contains" while ^= is "starts-with".
Unoti
+1  A: 

You're so close! This is what you want, the *= selector. http://api.jquery.com/category/selectors/

Like this:

$('*[class*=block-container]').fadeOut();

I tested it on a page that has . And then did: $('[class=opmen]').fadeOut();

And it faded out the topmenu div.

Unoti
+1 - Because I know you were working on this at the same time as Mark Ursino since you included the '*' before the first '[' that i editted out right after posting.
JMC