views:

28

answers:

2

hi all,

how can i select items with a classname that contains spaces? like <a href='button normal'>

thx

+3  A: 

I'm assuming your example meant class="" rather than href="" here.

You can select them using the attribute-contains selector (class is just another attribute in this case). The use looks like this (change or remove the a part if needed):

$("a[class*=' ']")
Nick Craver
+1  A: 

CSS3 has various attribute selectors, which work in jQuery. Most of them don't treat spaces in any special way; $('a[class="button normal"]') will select the link whose class attribute is exactly button normal. Or if you want to select elements which have button and normal classes (and possibly several more), use $('.button.normal'). (This is also plain old CSS, but does not work in IE6 due to a bug - the jQuery version does.)

Tgr