Why can’t .attr() change the value of value?
$("input").attr("value") = "New text";
See also a live jsfiddle example
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general: Because the value attribute sets the default value, not the current value. Use the
val()method instead.In your specific case (because the value hasn’t be changed by the user): because the
attrmethod doesn’t give you something you can assign a value to (and can’t be written in such a way as would allow you to). It takes two arguments, the second of which is the value you want to assign.