How to get output in p tag?

Viewed 70

Why this code doesn't get any outputs in p Tag? Please explain it

const inputName = document.getElementById("inputName");
const btnShow = document.getElementById("btnShow");
const pShow = document.getElementById("pShow");

btnShow.addEventListener("click", () => {
  const text = inputName.Value;
  pShow.textContent = text;
});
console.log(inputName, btnShow, pShow);
1 Answers

Input elements have value property and not Value, do it like this:

const inputName = document.getElementById("inputName");
const btnShow = document.getElementById("btnShow");
const pShow = document.getElementById("pShow");

btnShow.addEventListener("click", () => {
  const text = inputName.value;
  pShow.textContent = text;
});
<input type="text" id="inputName">
<button id="btnShow">Click Me!</button>

<p id="pShow"></p>

Related