Dementic Dementic - 2 months ago 12
jQuery Question

applying the same .click event to two diffrent divs

i have two diffrent 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 isnt 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')});

Answer

Simply:

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

See Multiple Selector.