Home  >  Article  >  Web Front-end  >  JS modified element display attribute example code

JS modified element display attribute example code

小云云
小云云Original
2018-03-12 16:05:423804browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn