Search code examples
yui3

Get nodeType of YUI 3 node


I was wondering if anybody can tell me the right way to check the node type of YUI3 node instance. ie node.nodeType==3 for text node etc.

Y.one('body').nodeType; //does not work

Thank you


Solution

  • OK I found out the solution. It's a bit ugly, but... Any property of an original DOM Node (ie. nodeType,NodeValue etc.) can be retrieved by calling get method:

    var type=Y.one("body").get('nodeType'); 
    alert (type);        //1 for element(3 for text etc)
    

    This is very useful for iterating over text/element nodes. Hope this helps someone!