Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get output in p tag?

Tags:

javascript

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);
like image 267
Alimuhammadiii Avatar asked May 13 '21 19:05

Alimuhammadiii


People also ask

How do I get text from p tag?

Use the textContent property to get the text of a paragraph element, e.g. const result = p. textContent . The textContent property returns the text content of the p element and its descendants. If the element is empty, an empty string is returned.

What tag to be used to get this output?

HTML <output> Tag.

What do the numbers in the <output> tag mean?

The numbers in the table specify the first browser version that fully supports the element. The <output> tag also supports the Global Attributes in HTML. The <output> tag also supports the Event Attributes in HTML. Most browsers will display the <output> element with the following default values:

What is <p> tag in HTML?

Definition and Usage The <p> tag defines a paragraph. Browsers automatically add a single blank line before and after each <p> element. Tip: Use CSS to style paragraphs.

What is the use of output tag in HTML?

The <output> tag is a new tag in HTML 5, and it requires a starting and ends tag. Attributes: The output tag accepts three attributes which are listed below: for: This attribute contains an attribute value element_id which is used to specify the relation between result and calculations.

What is the use of p&gt in HTML?

HTML &lt;p&gt; Tag 1 Definition and Usage. The <p> tag defines a paragraph. ... 2 Browser Support 3 Global Attributes. The <p> tag also supports the Global Attributes in HTML. 4 Event Attributes. The <p> tag also supports the Event Attributes in HTML. 5 More Examples. ... 6 Related Pages 7 Default CSS Settings


Video Answer


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>
like image 101
Manas Khandelwal Avatar answered Oct 23 '22 17:10

Manas Khandelwal