Setting innerHTML vs. setting value with Javascript

Solution 1:

Setting the value is normally used for input/form elements. innerHTML is normally used for div, span, td and similar elements.

Here is a link showing the use of ID.value: http://www.javascript-coder.com/javascript-form/javascript-form-value.phtml

Solution 2:

value is for form elements, innerHTML if you want to set the content of any other element.
There's also innerText if you want to set the text content (you won't have to escape anything in there, but no HTML works in there)

Solution 3:

value is generally a property of specific i/o elements such as input elements (also including the type="hidden").

elements which are not such as div, p, a, etc. generally don't even have the value property and even if a value is set, does not affect the final output.

Solution 4:

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 5:

value represents the value that would be GETed or POSTed for input elements. innerHTML could change the contents actual elements.