views:

39

answers:

2

hi i have a page which generate check boxes dynamically and i have the following event which fires every time a user click on any of the check boxes

$(':checkbox').click(function() {

 });

My question is how can i get the text of the check box that has been trigger by the user?
Thank you

A: 

found the solution

$(':checkbox').click(function() {
   alert( $(this).parent().find("label").text());
 });
CliffC
lol!.... there could be many label... if you did `.next()` or `.prev()`, it would be close... ;) but still, the OP is asking for a text on a checkbox, which is confusing.. ;)
Reigel
+1  A: 

Taking @CliffC query and changing it, This should work. Its an explicit query so you will always get the correct label

$(':checkbox').click(function() {

 alert( $(this).parent().find("label[for=" + this.id +"]").text());
});
skyfoot