Alex Ivasyuv Alex Ivasyuv - 6 months ago 23
jQuery Question

jQuery's val() method change doesn't seem to change the DOM

Doing

$("#someId").val("newValue")
doesn't change the DOM --
I can retrieve this value with
$("#someId").val()
, but the element in the DOM still doesn't have a value attribute.

How do I set the value of an input component and also change the DOM?

I'm using
jQuery 1.5.1
.

rsp rsp
Answer

.val() does change the DOM. For example this:

$("#someId").val("newValue");

alert(document.getElementById('someId').value);

alerts 'newValue'.

See DEMO.

If you want to change the default value to be used in form resets, try this:

$("#someId").attr("defaultValue", "newValue");

See DEMO.

Comments