-2

I've been trying to create this click event the way I described it but what I keep getting is a prompt message instead of a paragraph inside the box layout provided underneath the button.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Manuel
  • 1
  • 2
    can you add your code – Prosy Arceno May 10 '21 at 00:50
  • Const btn=document.getElementById("btn"); const paragraph=document.getElementById("paragraph"); btn.addEventListener("click", function() { paragraph.textContent="some text"}); – Manuel May 10 '21 at 21:41
  • Const btn=document.getElementById("btn"); const paragraph=document.getElementById("paragraph"); btn.addEventListener("click", function() { paragraph.textContent="some text"}); – Manuel May 10 '21 at 21:41

1 Answers1

2

Add a div for the box. Add an input textarea for the paragraph you will add. And a button to actually add your paragraphs.

const btn = document.getElementById("btn"); 
  const clr = document.getElementById("clr"); 
  const paragraph = document.getElementById("paragraph"); 
  const will_add = document.getElementById("will_add"); 
  var the_paragraph = "";

  btn.addEventListener("click", function() { 

    the_paragraph = the_paragraph + will_add.value; 
    paragraph.innerHTML = the_paragraph; 
  });

  clr.addEventListener("click", function() { 
    will_add.value = "";
    the_paragraph = ""; 
    paragraph.innerHTML = ""; 
  });
.box {
  height: 200px;
  width: 400px;
  border: 1px solid red;
  border-radius: 4px;
}

textarea {
  height: 50px;
  width: 400px;
}
<div class="box">
  <p id="paragraph"></p>
</div>

<textarea id="will_add" type="textarea" placeholder="Add your paragraph here..."></textarea>
<br/>
<button id="btn">Add</button>
<button id="clr">Clear</button>
Prosy Arceno
  • 2,616
  • 1
  • 8
  • 32