[dojo-contributors] DOM NodeType values not in 0.9

Adam L. Peller adam at peller.org
Fri Jun 8 15:39:33 EDT 2007


I don't see this as necessary and size counts -- it increases the size
of the expression from one byte to twenty one.  I might even prefer
"1".  You don't see the others very often, especially beyond "4".

-Adam

On 6/8/07, Brad Neuberg <paperairplane at gmail.com> 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;
>
> 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
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
>



More information about the dojo-contributors mailing list