Domanda

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.

È stato utile?

Soluzione

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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top