The method for JavaScript to control the hiding of elements is to set the display in the element's style attribute, such as [var t = document.getElementById('test');t.style.display = 'none';].
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
We have two ways to hide elements in javascript:
Method 1: Set the display in the element style attribute
var t = document.getElementById('test');//选取id为test的元素 t.style.display = 'none';// 隐藏选择的元素 t.style.display = 'block';// 以块级样式显示
Method 2: Set the element in the style attribute visibility
var t = document.getElementById('test'); t.style.visibility = 'hidden';// 隐藏元素 t.style.visibility = 'visible';// 显示元素
The difference between these two methods:
The original position will not be occupied after setting display to hide, but the element position will still be occupied after hiding through visibility.
Recommended learning: javascript video tutorial
The above is the detailed content of What is the method to control the hiding of elements in javascript. For more information, please follow other related articles on the PHP Chinese website!