Skip to content
Advertisement

Search a table looking for labels

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:

<asp:DropDownList ID="cboEvaporatorChoice" runat="server" class="cboBoxes"
Width="130px" AutoPostBack="True" onchange="clearLabels(MainTable)"></asp:DropDownList>
                                

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:

 function clearBox(ID) {
 var element = document.getElementsByTagName(ID);
 }  

               

Advertisement

Answer

function clearLabels(ID) {
    var labels = document.getElementById(ID).getElementsByTagName('label');
    for(var i = 0; i < labels.length; i++)
        labels[i].style.display = 'none';
}  

Or if you are using jQuery

$('#' + ID).find('label').hide();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement