Search code examples
javascriptdomyui3

How can I normalise a JavaScript object to a DOM element with YUI3?


YUI2's Dom.get accepts both a DOM element or an id string as a parameter. In YUI3, Y.one is the replacement for Dom.get but it only accepts CSS selectors, not DOM elements. Is there a simple way, using YUI3, to normalise a JavaScript object to a DOM element?


Solution

  • To support the same signature as YAHOO.util.Dom.get you could do something like this:

    var getNode = function(el) {
        return Y.one('#' + el) || new Y.Node(el);
    };
    

    Here's an example of the function above in use.