views:

64

answers:

2
$('#check1,#check2').click(function() {

});

Live above,how to tell if "check1" or "check2" is clicked ?

+5  A: 

On event handler functions, the context (the this keyword) within the function, represents the HTML Element that triggered the event.

You can:

$('#check1,#check2').click(function() {
  var id = $(this).attr('id'); // or simply this.id
});
CMS
this.id would have also worked
David Andres
Sure, since `this` is the HTMLElement
CMS
+1  A: 

Inside your function you can get the ID of the element and compare..

if($(this).attr("id") == "check1") ...
Quintin Robinson