Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style>
- #div1, #div2{
- display:none;
- }
- </style>
- </head>
- <body>
- <h2>An example of onchange event</h2>
- <div id="div1">
- <strong> I can be visible and invisible</strong>
- </div>
- <br>
- <div id="div2">
- <strong> I am the second text</strong>
- </div>
- <br>
- <select id="dropdown">
- <option value="one">One</option>
- <option value="two">Two</option>
- </select>
- <script>
- let select = document.querySelector("#dropdown");
- select.addEventListener("change", (e)=>{
- if (e.target.value==="one"){
- document.getElementById("div1").style.display = "block";
- document.getElementById("div2").style.display = "none";
- }
- else if(e.target.value==="two"){
- document.getElementById("div2").style.display = "block";
- document.getElementById("div1").style.display = "none";
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement