Getting messy with jquery traversal - Is there a neater way

curse

New Member
Just a quick question as I haven't been using jQuery for that long.Is there a neater/quicker way to get to the html for a label in this scenario.Here is a dumbed down version as an example,\[code\]<tr> <td> <label>Please fill in name:</label> </td> <td> <input type="text" id="txtName" class="validate" /> </td></tr><tr> <td> <label>Date of Birth:</label> </td> <td> <input type="text" id="txtDOB" class="validate" /> </td></tr>\[/code\]This is the jquery snippet i'm using currently to grab the html for the labels.\[code\]$(document).ready(function(){ $('.validate').each(function(){ if(!$(this).val()) { var label = $(this).parent().prev().find('label').html(); alert(label); } }); });\[/code\]Any ideas are appreciated
 
Back
Top