简体   繁体   中英

How you Hide/Show a table's borders in Javascript or JQuery

I want to hide and display a border in a table using JS or Jquery but am unable to do it, any assistance please.

<table Id="IdTable" name="nameTable">
    <tr><td>Name</td><td>Age</td></tr>
    <tr><td>Joseph</td><td>35</td></tr>
</table>

I've tried

document.getElementById("IdTable").style.border=1;

$("#IdTable").css.apply("border", "1");

I'm doing it so that you turn on and off the borders.

border is attribute so use as

 //document.getElementById("IdTable").style.border=1; $('#IdTable').css('border', '1px solid');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table Id="IdTable" name="nameTable"> <tr><td>Name</td><td>Age</td></tr> <tr><td>Joseph</td><td>35</td></tr> </table>

border is an attribute. so try

 document.getElementById("IdTable").border = 1;
 <table Id="IdTable" name="nameTable"> <tr> <td>Name</td> <td>Age</td> </tr> <tr> <td>Joseph</td> <td>35</td> </tr> </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM