tags:

views:

70

answers:

5

If a div tag looks like:

<div class="class1 class2">blah</div>

Isn't this suppose to still work?

$(".class2").bind("click", .... );

Or does having multiple classes for a element screw things up?

+2  A: 

Yes, this will still work regardless of how many classes are on the tag.

Andy Baird
+1  A: 

Should work just fine.

scunliffe
+1  A: 

Yes, that will work fine as long as you are aware that it will bind the click event for every element that has ".class2" set.

Why? What's happening?

Phil.Wheeler
ok I guess I have a bug somewhere else, thanks.
mrblah
A: 

I've tested your code in both IE8 and Firefox 3.5.3, and it works perfectly.

If it's not working for you, there must be some other reason for that.

RichieHindle
+1  A: 

Multiple classes on an element are valid. The following should illustrate some examples to help understand the JQuery class selector.

<div class="class1">one</div>
<div class="class2">two</div>
<div class="class1 class2">three</div>

Then

//will bind to the first and third div    
$(".class1").bind("click", .... );

//will bind to the second and third driv
$(".class2").bind("click", .... );

//will bind to only the third div, you get only elements that have BOTH classes
$(".class1.class2").bind("click", ....);

//will bind to all divs, you get elements with class1 along with elements with class2
$(".class1, .class2").bind("click", ....);
Bela