[dojo-contributors] DOM NodeType values not in 0.9

Alex Russell alex at dojotoolkit.org
Sat Jun 9 07:27:34 EDT 2007


On Friday 08 June 2007 12:08 pm, Brad Neuberg wrote:
> 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;

It's 100% intentional. Having them be public properties means that 
there's no chance for your code to be shortened when using them, and 
they're long-ass names anyway.

> 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);
> 	}
> }

That whole thing should be re-written as:

	dojo.query("#top >").orphan(".status");

> 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?

Nope.

Regards

-- 
Alex Russell
alex at sitepen.com     A99F 8785 F491 D5FD 04D7 ACD9 4158 FFDF 2894 6876
alex at dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20070609/b7031a8b/attachment.sig 


More information about the dojo-contributors mailing list