Javascript examples for jQuery:Form Input
Closest() returning the closest label to my input
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script> $(document).ready(function () { $(':input').each(function () { console.log($(this).closest('div#q2').find('.question_label').text()); });/*from w w w . j ava2 s .c om*/ }); </script> </head> <body> <div id="q2"> <label class="question_label">Label q2</label> <br> <input type="text"> </div> </body> </html>