i have this html.
<tr>
<td width="75">Mon</td>
<td class="bn_time" width="60">
<input id="mon_open" name="mon_open" class="time" placeholder="opening time" />
</td>
<td class="bn_time" width="10" align="center">-</td>
<td class="bn_time" width="100">
<input id="mon_close" name="mon_close" class="time" placeholder="closing time" />
</td>
<td colspan="3" align="center" class="bn_holiday" hidden>Holiday</td>
<td>
<input type="checkbox" name="mon_closed" id="mon_closed" class="bn_closed" />
<label for="mon_closed">Closed</label>
</td>
</tr>
what i am trying to do is using change event for checkbox add/remove' hidden attribute to` element. for example.
if ('#bn_closed').is(':checked') {
//hide all <td> element with class bn_time
//show <td> element with class bn_holiday
} else {
//show all <td> element with class bn_time
//hide <td> element with class bn_holiday
}
this is what i tried to do using jQuery.
$('.bn_closed').change(function() {
var element = $(this);
var id = element.attr('id');
var day = id.slice(0,-7);
var day_open = day+'_open';
var day_close = day+'_close';
if(element.is(':checked')) {
//hide all <td> element with class bn_time
//show <td> element with class bn_holiday
} else {
//show all <td> element with class bn_time
//hide <td> element with class bn_holiday
}
});
there is on important thing to note, there are multiple element with the same class name. i want to modify the attribute of element of just siblings not all that is in the table.
thank you.
1 Answer