HTML input value attribute - same input, (apparently) different results

How does the value attribute work for an html input tag after editing through an input field?

Example:

<input type="text" name="test" id="test" value="Hello world" />

an input window appears with the text "Hello world". If I edit it by entering a new line into the processed text field (and not through the source code), and then try to get its value using js, like this

alert(document.getElementById('test').value)

I, correctly, get a new meaning. But if I check the item through the developer’s chrome tools (or firebug, or whatever you prefer), I will see the same “Hello world” line as it was at the beginning.

Which of the two are correct? js or chrome inspector?

Here is an example script and here is a screenshotenter image description here

, : , X, X. , : OLD NEW val , , . /.

, attr. "" "" , , , .

- ? "" - ?

+5
3

, .

DOM value .

HTML value ( , DOM defaultValue ).

Chrome DOM HTML. , .

Screen shot of Chrome property view

+8

.

, html, , . , DOM , ele.setAttribute( "", " " )

, , onchange , , .

+5

You can assign a so-called proprietary attribute; for example "oldval" so that later you can compare it with the current value

+1
source

All Articles