Home >Web Front-end >Front-end Q&A >How to hide
The
1. Use CSS to hide the
CSS is a very powerful style language that can control the display and layout of elements in HTML. It can be hidden by setting the display attribute of the
So, if we want to hide a
tr.hide { display: none; }
After adding this line of CSS, we can add a class name to the
2. Use JavaScript to hide the
In addition to using CSS, we can also use JavaScript to dynamically hide the
The row can be hidden or shown by setting the style.display attribute of the
// 隐藏 document.getElementById("trId").style.display = "none"; // 显示 document.getElementById("trId").style.display = "table-row";
The advantage of this method is that it is simple and easy to understand. The disadvantage is that the style of the element needs to be directly manipulated in the JavaScript code. When the style needs to be modified, the JavaScript code needs to be modified.
We can control the display and hiding of elements by adding or removing a class name, as follows Shown:
tr.hide { display: none; }
// 隐藏 document.getElementById("trId").classList.add("hide"); // 显示 document.getElementById("trId").classList.remove("hide");
The advantage of this method is that you can use CSS to manage styles, making the code clearer and easier to maintain.
3. Summary
Through the above two methods, we can achieve the effect of hiding the
The above is the detailed content of How to hide