简体   繁体   中英

How to make paragraph visible when click on button?

¨ I need that when click button it appear my paragraph

      <button class="con-button" type="button">SUMBIT</button>
      <p id="d-c" class="d-c">Thanks for contacting <strong>Deni Beatz</strong>,your message has been sent 6 <u>Reply of Deni Beatz will be send you on mail with <strong>Contact</strong> on fastest type possible</u></p>
      <script>
        
      </script>

¨

Assign a eventListener to your button and afterwards use the toggle funktion. take aa look to the exmaple below:

 const btn = document.querySelector('.con-button'); btn.addEventListener('click', () => { const dc = document.querySelector('#d-c'); dc.classList.toggle('hide') })
 .hide { display: none; }
 <button class="con-button" type="button">SUMBIT</button> <p id="dc" class="dc">Thanks for contacting <strong>Deni Beatz</strong>,your message has been sent 6 <u>Reply of Deni Beatz will be send you on mail with <strong>Contact</strong> on fastest type possible</u></p>

you can implement this as follows:

HTML

<button id="myButton" onclick="showParagraph()">SUMBITe</button>
<p id="myParagraph" style="display: none;">This is a paragraph.</p>

JS

function showParagraph() {
  document.getElementById("myParagraph").style.display = "block";
}

you can use getElementByClassName too. here I presented an Id for elements. if you want to hide the paragraph again you can use a condition and change "block" to "none"

  <button class="con-button" type="button" onClick = "visiBiliti()"enter code here>SUMBIT</button>
    <p id="d-c" class="d-c">Thanks for contacting <strong>Deni 
       Beatz</strong>,your message has been sent 6 <u>Reply of Deni Beatz will 
      be send you on mail with <strong>Contact</strong> on fastest type p 
      possible</u>
   </p>
      <script>
        const visiBiliti = ()=>{
          document.getelementById("d-c").style.visibiliti="visible"
        }
      </script>

 function hideP(){ document.getElementById("dc").style.display = "none" }
 <button class="con-button" onclick="hideP()" type="button">SUMBIT</button> <p id="dc" class="dc">Thanks for contacting <strong>Deni Beatz</strong>,your message has been sent 6 <u>Reply of Deni Beatz will be send you on mail with <strong>Contact</strong> on fastest type possible</u></p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM