I have a bunch of these little bits of HTML code repeated over and over again:
<div class="collapse" id="any_mins">
<fieldset>
<legend><img title="Click to expand" class="plus" alt="+" src="" />Heading</legend>
<table class="mins_table">
lots of rows and cells go here
</table>
</fieldset>
</div>
Inside the tables there are form elements, mainly textboxes and selects. I have a bit of jQuery that makes the <legend>
heading highlighted if there are non-blank form elements in the containing table. It looks like this:
// input td tr tbody table legend img
$("input[type='text'][value!=0]").parent().parent().parent().parent().show();//the table
$("input[type='text'][value!=0]").parent().parent().parent().parent().siblings().children().attr("src", minus_path);//the image
$("input[type='text'][value!=0]").parent().parent().parent().parent().siblings().addClass("highlighted")//the legend
// option select td tr tbody table legend img
$("option:selected[value!=0]").parent().parent().parent().parent().parent().show();//the table
$("option:selected[value!=0]").parent().parent().parent().parent().parent().siblings().children().attr("src", minus_path);//the image
$("option:selected[value!=0]").parent().parent().parent().parent().parent().siblings().addClass("highlighted")
This works, but is obviously the wrong way. Whats the right way?