Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dynamic HTML
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Example: Displaying an additional block of text == The following code illustrates an often-used function. An additional part of a web page will only be displayed if the user requests it. <syntaxhighlight lang="html"> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Using a DOM function</title> <style> a { background-color: #eee; } a:hover { background: #ff0; } #toggleMe { background: #cfc; display: none; margin: 30px 0; padding: 1em; } </style> </head> <body> <h1>Using a DOM function</h1> <h2><a id="showhide" href="#">Show paragraph</a></h2> <p id="toggle-me">This is the paragraph that is only displayed on request.</p> <p>The general flow of the document continues.</p> <script> function changeDisplayState(displayElement, textElement) { if (displayElement.style.display === "none" || displayElement.style.display === "") { displayElement.style.display = "block"; textElement.innerHTML = "Hide paragraph"; } else { displayElement.style.display = "none"; textElement.innerHTML = "Show paragraph"; } } let displayElement = document.getElementById("toggle-me"); let textElement = document.getElementById("showhide"); textElement.addEventListener("click", function (event) { event.preventDefault(); changeDisplayState(displayElement, textElement); }); </script> </body> </html> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)