What is innerHTML on input elements?
Solution 1:
Setting the value
is normally used for input/form elements. innerHTML
is normally used for div, span, td and similar elements.
value
applies only to objects that have the value attribute (normally, form controls).
innerHtml
applies to every object that can contain HTML
(divs, spans, but many other and also form controls).
They are not equivalent or replaceable. Depends on what you are trying to achieve
Solution 2:
First understand where to use what.
<input type="text" value="23" id="age">
Here now
var ageElem=document.getElementById('age');
So on this ageElem
you can have that many things what that element contains.So you can use its value
,type
etc attributes. But cannot use innerHTML because we don't write anything between input tag
<button id='ageButton'>Display Age</button>
So here Display Age
is the innerHTML content as it is written inside HTML tag button.