Skip to content

Commit

Permalink
Only set value as innerHTML if the element is a TEXTAREA and support …
Browse files Browse the repository at this point in the history
…setting the value of SELECT elements.
  • Loading branch information
Felix Gnass committed Oct 5, 2010
1 parent 3e31798 commit bf4d1c7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/jsdom/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,21 @@ var browserAugmentation = exports.browserAugmentation = function(dom, options) {
});

dom.Element.prototype.__defineSetter__('value', function(val) {
this.nodeValue = this.innerHTML = val;
return this.setAttribute('value', val);
});

if (this.nodeName.toUpperCase() == 'INPUT') {
this.setAttribute('value', val);
} else if (this.nodeName.toUpperCase() == 'TEXTAREA') {
this.nodeValue = this.innerHTML = val;
} else if (this.nodeName.toUpperCase() == 'SELECT') {
for (var i = 0; i < this.options.length; i++) {
if (this.options[i].value == val) {
this.selectedIndex = i;
}
}
} else {
//Throw Error
}
});

dom.Element.prototype.__defineGetter__('textContent', function() {
var stripHTML = /<\S[^><]*>/g;
var out = this.innerHTML;
Expand Down

0 comments on commit bf4d1c7

Please sign in to comment.