Home computickets show and hide div on click on button

show and hide div on click on button

Author

Date

Category

There is a code
HTML:

$ (document) .ready (function () {
  $ ("# showHideContent"). click (function () {
    if ($ ("# content"). is (": hidden")) {
      $ ("# content"). show ("slow");
    } else {
      $ ("# content"). hide ("slow");
    }
    return false;
  });
});
  
& lt; script src = "https://ajax.googleapis.com/ajax/libs /jquery/1.2.3/jquery.min.js"></script>
& lt; button id = "showHideContent" & gt; Show / Hide & lt; / button & gt;
& lt; div id = "content" style = "display: none;" & gt; Content that is hidden by default. Shows / hides when clicking on the same link. & Lt; / div & gt; 

Answer 1, authority 100%

Here’s what I needed, maybe someone needs it:

let content = document.getElementById ("content")
let show = document.getElementById ("showContent")
let hide = document.getElementById ("hideContent")
show.addEventListener ("click", () = & gt; {
  content.style.display = "block"
})
hide.addEventListener ("click", () = & gt; {
  content.style.display = "none"
})
    
& lt;! DOCTYPE html & gt;
& lt; html lang = "ru" & gt;
  & lt; head & gt;
    & lt; title & gt; No Title & lt; / title & gt;
    & lt; meta charset = "utf-8" & gt;
& lt; / head & gt;
  & lt; body & gt;
    & lt; button id = "showContent" & gt; Show & lt; / button & gt;
    & lt; button id = "hideContent" & gt; Hide & lt; / button & gt;
    & lt; div id = "content" style = "display: none;" & gt; Content that is hidden by default. Shows / hides when clicking on the corresponding buttons. & Lt; / div & gt;
  & lt; / body & gt;
& lt; / html & gt; 

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions