Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How javascript hides html elements

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how javascript hides html elements". In daily operation, I believe many people have doubts about how javascript hides html elements. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how javascript hides html elements". Next, please follow the editor to study!

Javascript hide html elements of the method: 1, create a new HTML file; 2, use the input tag to define a type of button button; 3, define a cki () function; 4, by setting the object style display attribute to none to achieve hiding.

This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer

How does javascript hide html elements?

JS implements the click of a button to hide the contents of the HTML element

Create a new HTML file, named test.html, to achieve the function of clicking the button to hide the P tag.

On the test.html page, use the p tag to define a piece of text content and add an id attribute to the p tag, with id as demo, making it easy for later steps to use JS to get the p tag object.

Then on the test.html page, use the input tag to define a button of type button that can be clicked to trigger a hidden function.

Bind a click event onclick to the input tag, and when the input button is clicked, call the cki () function of JS.

Add a JS tag to the test.html page, define a cki () function inside the tag, and write code in it to achieve the function of clicking to hide the p tag.

In the cki () function, the p-tag object is obtained by using the document.getElementById () method, and the function of hiding the p-tag is realized by setting the display property in the object style to none.

Run the test.html file on the browser to see the effect of the implementation:

It can be seen that it is successful to click the button to hide the content of the p tag.

At this point, the study on "how javascript hides html elements" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report