JavaScript
Article

jquery get label text associated with checkbox

By Sam Deering

Simple jQuery code snippet to get label text associated with checkbox.

console.log($('label[for="carHireChk"]').html());
$("label[for='comedyclubs']")
$("label[for=' + this.attr("id") + ']").attr('class', 'error');

See doco for more info: http://api.jquery.com/next-adjacent-Selector/

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.