Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#974 closed defect (fixed)

dojo.dom.textContent doesn't work with an empty string

Reported by: andy@… Owned by: liucougar
Priority: high Milestone:
Component: DOM Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

if you pass the empty string to dojo.dom.textContent, it doesn't replace the text. I.e. dojo.dom.textContent(node,"") doesn't clear the contents of the node. You can work around it at the moment by passing " ". Looking at the code, I guess that (text) is evaluating to false here - maybe it needs to be 'if (text!=undefined) {...' or something like that.

dojo.dom.textContent = function(node, text){

if (text) {

dojo.dom.replaceChildren(node, document.createTextNode(text)); return text;

} else {

var _result = ""; if (node == null) { return _result; } for (var i = 0; i < node.childNodes.length; i++) {

switch (node.childNodes[i].nodeType) {

case 1: ELEMENT_NODE case 5: ENTITY_REFERENCE_NODE

_result += dojo.dom.textContent(node.childNodes[i]); break;

case 3: TEXT_NODE case 2: ATTRIBUTE_NODE case 4: CDATA_SECTION_NODE

_result += node.childNodes[i].nodeValue; break;

default:

break;

}

} return _result;

}

}

Change History (4)

comment:1 Changed 13 years ago by dylan

Component: GeneralDOM
Milestone: 0.5

comment:2 Changed 13 years ago by liucougar

Milestone: 0.50.4
Owner: changed from anonymous to liucougar

comment:3 Changed 13 years ago by liucougar

Resolution: fixed
Status: newclosed

fixed in r5074

comment:4 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.