$('#id').val() = $.cookie("name");
- not works, nothing changes
document.getElementById('id').value = $.cookie("name");
- works fine
Why?
$('#id').val() = $.cookie("name");
- not works, nothing changes
document.getElementById('id').value = $.cookie("name");
- works fine
Why?
Share Improve this question edited Mar 27, 2011 at 21:54 Diodeus - James MacFarlane 114k33 gold badges163 silver badges180 bronze badges asked Mar 27, 2011 at 21:52 AlexAlex 154 bronze badges4 Answers
Reset to default 8You are not directly accessing the elements value. The left hand side of your expression is a getter which evaluates to a literal. So the expression is parable to something like 5 = 10
, which obviously cant work
$('#id').val() = $.cookie("name");
val()
is overloaded, and by giving it an argument you can reassign
$('#id').val($.cookie("name"));
try to use
$('#id').val($.cookie("name"));
You are using the getter version of val() when you call it with no arguments.
Use $('#id').val($.cookie("name"));
instead.
$('#id').val($.cookie("name"));