document.getElementById("test").value
document.getElementById("test").innerHTML
Does the first mean the address and the second mean the value stored at the address? Also, where can I find documentation on the value
property?
value gives you the currently-set value of a form element (input, select, textarea), whereas . innerHTML builds an HTML string based on the DOM nodes the element contains.
The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM. It is used almost every time you want to read or edit an HTML element.
The innerHTML is a property of the Element that allows you to get or set the HTML markup contained within the element: element.innerHTML = 'new content'; element.innerHTML; Code language: JavaScript (javascript)
The innerHTML property is part of the Document Object Model (DOM) that allows Javascript code to manipulate a website being displayed. Specifically, it allows reading and replacing everything within a given DOM element (HTML tag).
.value
gives you the currently-set value of a form element (input
, select
, textarea
), whereas .innerHTML
builds an HTML string based on the DOM nodes the element contains.
For a simple example, go to the JS Fiddle demo, and enter a new value into the input
and then move out of the input.
The test uses the following JavaScript:
document.getElementById('input').onchange = function(){
alert('innerHTML: ' + document.getElementById('input').innerHTML + '; whereas value: ' + document.getElementById('input').value);
};
(The above text updated, following a comment left by am not i am, in comments below.)
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