I am trying to search a table looking for all the labels in that table. When the JavaScript function finds a label I want to set it’s visibility to false.
My html code looks like this:
JavaScript
x
4
1
<asp:DropDownList ID="cboEvaporatorChoice" runat="server" class="cboBoxes"
2
Width="130px" AutoPostBack="True" onchange="clearLabels(MainTable)"></asp:DropDownList>
3
4
My function is called on a drop down lists onchange
event which then passes the table that holds all the labels I want to hide.
I am not sure what my JavaScript code should look like… This is all I have:
JavaScript
1
6
1
function clearBox(ID) {
2
var element = document.getElementsByTagName(ID);
3
}
4
5
6
Advertisement
Answer
JavaScript
1
6
1
function clearLabels(ID) {
2
var labels = document.getElementById(ID).getElementsByTagName('label');
3
for(var i = 0; i < labels.length; i++)
4
labels[i].style.display = 'none';
5
}
6
Or if you are using jQuery
JavaScript
1
2
1
$('#' + ID).find('label').hide();
2