When we want to use JS to control the display attribute of an element to show or hide it, we need to apply the display attribute to the interline style. This article mainly shares with you the example code of JS modifying the display attribute of the element. I hope it can help. Everyone.
And use the ID selector
That is,
<p id="drop-box" style="display:none"> 在JS文件中, var dropBox = document.getElementById("drop-box"); //设置元素显示 function showBox(){ dropBox.style.display = "block"; } //设置元素隐藏 function hideBox(){ dropBox.style.display = "none"; }
Related recommendations:
Flex layout method of display attribute in CSS3
js method of hiding controls and introduction to display attributes_javascript skills
jquery controls the display attribute to none or block_jquery
The above is the detailed content of JS modified element display attribute example code. For more information, please follow other related articles on the PHP Chinese website!