Permalink
Browse files

Change text content rather than re-add text node in text() method

  • Loading branch information...
1 parent 7059883 commit 61f6555f320e40f16b0da0984a95f0b26e6965ac @ilinsky ilinsky committed Apr 3, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 ample/runtime/modules/manipulation.js
@@ -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;
}

0 comments on commit 61f6555

Please sign in to comment.