Search code examples
javascriptyuiyui3

YUI 3: How to get native DOM element wrapped inside Node?


I've used this simple technique to get a native DOM element in jQuery:

var el = $('#myid');
var native = el[0];  //or el.get(0);

How can I do this in YUI 3? For example, I want to use getElementsByName DOM method, which is not supported by YUI 3.


Solution

  • var el = Y.one("#myid");
    var native = el.getDOMNode();
    

    If you can't be confident that '#myid' is in the DOM then you should check for null first. YUI's .one doesn't chain like in jQuery.

    var el = Y.one("#myid"), native;
    if (el !== null) {
        native = el.getDOMNode();
    }