I want to get the value of a <p/>
element using JavaScript, but instead, I get undefined
:
HTML:
<p id="bool_"> _test_</p>
JavaScript:
var x = document.getElementById("bool_").value;
alert(x); // Alerts 'undefined'
Try using the innerText
property of a HTML element.
const x = document.getElementById("bool_").innerText;
alert(x);
您正在寻找的是
var x =document.getElementById("bool_").innerHTML;
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.