user385729
user385729

Reputation: 1984

get the text next to checkboxes in javascript/JQuery

Is there any way that I can get "Enable Recruiters to directly contact me" in Javascript or JQuery when the checkbox checked?

I know I can get the value easily, but how about the text beside that which can be in a lable?

<input type="checkbox" name="rec" id="rec" value="ON"><label for='rec'>Enable Recruiters to directly contact me</label>

Please let me know if you need more clarification!

Upvotes: 0

Views: 239

Answers (1)

Adil
Adil

Reputation: 148110

You can bind the change event and use the event source object to call next on it to get the label next to checkbox.

Live Demo

$('#rec').change(function(){
   if(this.checked)
    alert($(this).next().text())    
})

Upvotes: 2

Related Questions