views:

329

answers:

3

I have two types of buttons that I want to use the same code block. Rather than create two event handlers is it possible to reference the buttons by doing something like this:

$(".lb",".da")

I've tried the specific example and it doesn't work but hopefully it'll give you an idea for what I'm aiming at doing.

TIA

Lloyd

+9  A: 

Yes, jQuery works just like CSS:

$(".lb, .da")

You can use commas to use multiple selectors, or a > to select a direct descendant:

$("#parent > ul")

There are many more, but this page at the W3C site details them pretty clearly. Check out Section 2 for a table with examples.

Doug Neiner
+3  A: 

The comma needs to be inside the selector string

$(".lb, .da")

Remember the selectors in jQuery are like CSS selectors, commas are standard syntax.

Matt
+1  A: 

Try: $(".lb, .da") instead, there shouldn't be quotes around each selector.

catfarm