Skip to content

Commit

Permalink
Change text content rather than re-add text node in text() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ilinsky committed Apr 3, 2012
1 parent 7059883 commit 61f6555
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ample/runtime/modules/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ cQuery.prototype.text = function(sValue) {
if (arguments.length > 0) {
// Replace children with a text node
fQuery_each(this, function() {
while (this.lastChild)
fElement_removeChild(this, this.lastChild);
var oText = null;
if (this.childNodes.length == 1 && (this.firstChild.nodeType == 3 || this.firstChild.nodeType == 4))
oText = this.firstChild;
else {
while (this.lastChild)
fElement_removeChild(this, this.lastChild);
oText = fElement_appendChild(this, fDocument_createTextNode(this.ownerDocument, ''));
}
// Add child
fElement_appendChild(this, fDocument_createTextNode(this.ownerDocument, cString(sValue)));
fCharacterData_replaceData(oText, 0, oText.length, cString(sValue));
});
return this;
}
Expand Down

0 comments on commit 61f6555

Please sign in to comment.