I have a checkbox in my page.
<input type="checkbox" name="fruit1" value="Mango" /><label for="fruit1">Mango</label>
How to get the associated label value for this CheckBox in JavaScript.
Hi makenzi.exc,
On CheckBox Click, find the label associated with the CheckBox using jQuery id attribute.
Refer below sample.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("input[type=checkbox]").click(function () { if ($(this).is(':checked')) { alert($("label[for='" + $(this).attr("id") + "']").text()); } }); }); </script> <input type="checkbox" id="fruit" value="1" /><label for="fruit">Mango</label> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.