Combine two selectors with a jQuery object
P粉122932466
P粉122932466 2024-03-27 15:40:35
0
2
285

I have two divs with ids: #addNew_tab and #sendCom_tab.

I want to click on any of them to trigger the same jQuery click() function.

I was thinking something like this:

$("#addNew_tab", "#sendCom_tab").click(function(){
      //do stuff
});

But this doesn't work.

P粉122932466
P粉122932466

reply all(2)
P粉245489391
function doStuff() {
    // do stuff
}

$("#addNew_tab").click(doStuff);
$("#sendCom_tab").click(doStuff);
P粉769413355
$("#addNew_tab, #sendCom_tab").click(function(){
      //do stuff
});

Changed from:

$("#addNew_tab", "#sendCom_tab")

To:

$("#addNew_tab, #sendCom_tab")

The comma inside the selector ("a, b") means the first plus the second; just like CSS selectors
(Well, it's a CSS selector...)

It is equal to:

$("#addNew_tab").add("#sendCom_tab")...
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template