How to get value of HTML element in javascript? -


so i'm having trouble getting value of specific field in code - made pretty simple example show problem, here jsfiddle: https://jsfiddle.net/c3jtg60v/

the html:

<p id="theinput">    desired-value </p> 

the javascript:

var value = document.getelementbyid("theinput").value; console.log(value); 

as is, have assigned p element id of "theinput", , in have desired value, want make use of in javascript.

at moment, i'm trying console.log value, when this, logged in console 'undefined'. want logged console "desired value",

any on appreciated!

edit: how lots of downvotes, , question people sending me to, "getting innerhtml value variable" - problem didn't know innerhtml, how know question relevant?? come on people!

.value refers value property, cannot set p tag. if want inner text of html tag, this:

var value = document.getelementbyid("theinput").innerhtml; 

Comments