views:

36

answers:

3

I'd like to listen on the event of a user clicking on a checkbox's title (in addition to the checkbox itself). How can this be done?

A: 
$('#myCheckbox').change(function(){ doStuff();});
$('#myCheckboxsLabel').click(function(){ doStuff();});

So long as you use the same doStuff() function for both, you should be ok

Jason
+5  A: 

If you wrap the title in a <label for="checkboxID">, then clicking on the title will fire the checkbox's click event.

See here for a quick example.

Matt
A: 

If <label for="id"> tags don't trigger your jQuery you may need a plugin to do it for you. Try labelify, I've heard good things (though not directly related to your question).

Matt S