Skip to content

Commit

Permalink
calling val() on non existent element should return undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
i8ramin committed Mar 28, 2012
1 parent 43dccd7 commit 27f33dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/zepto.js
Expand Up @@ -333,7 +333,7 @@ var Zepto = (function() {
},
val: function(value){
return (value === undefined) ?
(this.length > 0 ? this[0].value : null) :
(this.length > 0 ? this[0].value : undefined) :
this.each(function(idx){
this.value = funcArg(this, value, idx, this.value);
});
Expand Down
2 changes: 2 additions & 0 deletions test/zepto.html
Expand Up @@ -1138,6 +1138,8 @@ <h1>Zepto DOM unit tests</h1>

input.val(function(i, val){ return val.replace('Hello', 'Bye') });
t.assertEqual('Bye again', input.val());

t.assertUndefined($('non-existent').val());
},

testChaining: function(t){
Expand Down

0 comments on commit 27f33dc

Please sign in to comment.