If I use this line in JavaScript,
$("#formfieldid").attr("value", "foobar");
It inserts the value attribute into the HTML such that it’ll appear when viewing the source.
If I use this line in JavaScript,
document.getElementById("formfieldid").value = "foobar";
The value of the field will be foobar, but it won’t show up under view source.
What I want to do is have the attribute NOT show up under view source and use jQuery. Does there exist an equivalent in jQuery?
Use
.prop()to set the property of elements as opposed to the attributeIf
.prop()(v1.6+) is not available use.val()as its a short cut for the value property.