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);
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.
HTML <output> Tag.
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:
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.
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.
HTML <p> 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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With