Permalink
Browse files

Merge pull request #28 from heycam/textcontent-setter

Implement Element.textContent setter.
  • Loading branch information...
2 parents d03dcdb + 05f7366 commit 9544e7d2a5464ad365e3768e47c1a3cf70ece450 @jindw committed Sep 3, 2012
Showing with 19 additions and 5 deletions.
  1. +6 −5 dom.js
  2. +13 −0 test/dom/element.js
View
11 dom.js
@@ -1088,12 +1088,13 @@ try{
switch(this.nodeType){
case 1:
case 11:
- var c = node.firstChild;
- while(c){
- node.removeChild(c)
- c = c.nextSibling;
+ while(this.firstChild){
+ this.removeChild(this.firstChild);
}
- return ;
+ if(String(data)!=''){
+ this.appendChild(this.ownerDocument.createTextNode(data));
+ }
+ break;
default:
//TODO:
this.data = data;
View
@@ -119,6 +119,19 @@ wows.describe('XML Namespace Parse').addBatch({
var str3 = new XMLSerializer().serializeToString(doc3);
console.assert(str1 == str3);
},
+ "set textContent":function() {
+ var doc = new DOMParser().parseFromString('<test><a/><b><c/></b></test>');
+ var a = doc.documentElement.firstChild;
+ var b = a.nextSibling;
+ a.textContent = 'hello';
+ console.assert(doc.documentElement.toString() == '<test><a>hello</a><b><c/></b></test>');
+ b.textContent = 'there';
+ console.assert(doc.documentElement.toString() == '<test><a>hello</a><b>there</b></test>');
+ b.textContent = '';
+ console.assert(doc.documentElement.toString() == '<test><a>hello</a><b/></test>');
+ doc.documentElement.textContent = 'bye';
+ console.assert(doc.documentElement.toString() == '<test>bye</test>');
+ },
"nested append failed":function(){
},
"self append failed":function(){

0 comments on commit 9544e7d

Please sign in to comment.