Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applying the same .click event to two different divs

Tags:

jquery

click

i have two different divs (code was simplified, this is not the actual code.)

<div id="test"></div>
<div id="funt"></div>

what i want is, to attach the same click event to #funt: something like:

$('#test').click(function() {
    DoWork();
});
$('#funt).click(function() {
    DoWork();
});

function DoWork(){
    alert('yes');
}

but isn't there a way to define multiple div's the same click event?

lets say ( yes, i know this does not work! )

($('#test'),('#funt')).click(function(){alert('yes')});

like image 787
Rafael Herscovici Avatar asked Jul 18 '11 11:07

Rafael Herscovici


1 Answers

Simply:

$("#test, #funt").click(DoWork);

See Multiple Selector.

like image 143
karim79 Avatar answered Sep 24 '22 12:09

karim79