admin管理员组

文章数量:1406020

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") 

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") 
Share Improve this question edited Aug 29, 2018 at 17:29 Louys Patrice Bessette 33.9k7 gold badges40 silver badges66 bronze badges asked Aug 29, 2018 at 16:23 Sumit RajguruSumit Rajguru 191 silver badge7 bronze badges 4
  • 2 What does this have to do with C#, asp or vb? – maccettura Commented Aug 29, 2018 at 16:26
  • 4 Need solution as soon as possible - Stack Overflow is not a free code-writing service. – Derek 朕會功夫 Commented Aug 29, 2018 at 16:26
  • 1 My code is in C#. yet all I see is HTML and JavaScript. What code is in c#? – Camilo Terevinto Commented Aug 29, 2018 at 16:27
  • before adding immature ment, develop a holistic thinking capability. thanx for ment though! – Sumit Rajguru Commented Aug 30, 2018 at 17:04
Add a ment  | 

2 Answers 2

Reset to default 5

Your three JavaScript examples aren't valid JavaScript. I remend 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>

You can simply use jQuery

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis./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>

本文标签: javascriptHiding a lttdgt depending on the ConditionStack Overflow