Sumit Rajguru
Sumit Rajguru

Reputation: 19

Hiding a <td> depending on the Condition

I have a table structure as given below:

<table>
 <tr>
  <td id="td1"> </td>
  <td id="td2"> </td>
  <td id="td3"> </td>
  <td id="td4"> </td> 
 </tr>
</table> 

I am checking some condition like:

if(a==2 || check == true) 

I want to hide the "td3" if any one condition satisfies.

My code is in C#.

I have already tried

document.getelementbyId("td3").style("display"= "none"),
document.getelementbyId("td3").display.hide();
td3.Attributes.add("style", "display:none") 

Upvotes: 1

Views: 6384

Answers (2)

Vishnu Chauhan
Vishnu Chauhan

Reputation: 301

You can simply use jQuery

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $('#td3').hide()
});
</script>
</head>
<body>

<table>
    <tr>
        <td id="td1">TD1</td>
        <td id="td2">TD2</td>
        <td id="td3">TD3</td>
        <td id="td4">TD4</td>
    </tr>
</table>
</body>
</html>

Upvotes: 0

Gary Thomas
Gary Thomas

Reputation: 2331

Your three JavaScript examples aren't valid JavaScript. I recommend reading the JavaScript docs a bit more in depth!

You can use the code below to hide the td.

document.getElementById("td3").style.display = "none";
<table>
    <tr>
        <td id="td1">TD1</td>
        <td id="td2">TD2</td>
        <td id="td3">TD3</td>
        <td id="td4">TD4</td>
    </tr>
</table>

Upvotes: 5

Related Questions