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粉2454893912024-03-28 14:55:36
function doStuff() { // do stuff } $("#addNew_tab").click(doStuff); $("#sendCom_tab").click(doStuff);
P粉7694133552024-03-28 14:17:39
$("#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")...