Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 898
Dan Avatar asked Nov 29 '12 13:11

Dan


1 Answers

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();
}
like image 193
Brian J. Miller Avatar answered Sep 30 '22 20:09

Brian J. Miller