[dojo-contributors] DOM NodeType values not in 0.9

Brad Neuberg paperairplane at gmail.com
Fri Jun 8 15:08:25 EDT 2007


I jost noticed that the old dojo.dom NODE_TYPE definition stuff is no
longer in 0.9:

dojo.dom.ELEMENT_NODE                  = 1;
dojo.dom.ATTRIBUTE_NODE                = 2;
dojo.dom.TEXT_NODE                     = 3;
dojo.dom.CDATA_SECTION_NODE            = 4;
dojo.dom.ENTITY_REFERENCE_NODE         = 5;
dojo.dom.ENTITY_NODE                   = 6;
dojo.dom.PROCESSING_INSTRUCTION_NODE   = 7;
dojo.dom.COMMENT_NODE                  = 8;
dojo.dom.DOCUMENT_NODE                 = 9;
dojo.dom.DOCUMENT_TYPE_NODE            = 10;
dojo.dom.DOCUMENT_FRAGMENT_NODE        = 11;
dojo.dom.NOTATION_NODE                 = 12;

Using these make for much more readable code when doing HTML DOM
manipulation. So you might have the following:

var top = dojo.byId("top");
for (var i = 0; i < top.childNodes.length; i++){
	var currentNode = top.childNodes[i];
	if (currentNode.nodeType == dojo.dom.ELEMENT_NODE &&
		currentNode.className == "status"){
		top.removeChild(currentNode);
	}		
}

rather than just if(currentNode.nodeType == 1)

It was a bug in the browsers not to include the standard DOM element
node values given by nodeType; they are correctly predefined in
Mozilla but not Internet Explorer, which was a bug and which is why
everyone uses the numbers in their code versus what the standard said
to do. Here are Mozilla's predefined values in the global object Node:
http://developer.mozilla.org/en/docs/DOM:element.nodeType , which
allowed you to just say Node.ELEMENT_NODE rather than '1'.

Can we put these values somewhere in the core?

Best,
  Brad



More information about the dojo-contributors mailing list