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

JS modified element display attribute example code

小云云
Release: 2018-03-12 16:05:42
Original
3834 people have browsed it

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";        }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template