In my HTML I have something like this
<input type="button" value="Delete" onclick="delete(this);"/>
and in the JavaScript file I define my function "delete" like this:
YUI().use('node', functioin(Y) {
function delete(el){
//Here is the problem
el.get('parentNode');
}
}
The problem is, I want to convert the "el" object (which is a normal JavaScript object) to a node of YUI 3 so that I can use YUI 3's functions more conveniently. And I don't know how to do it.
What is the solution?
YUI 3’s
Y.Node
constructor can simply take in a DOM element or selector string and return a newY.Node
instance:But, the preferred way is the use the convenient
Y.one
factory method:Also, YUI 3 has a
Y.NodeList
class which represents a collection ofY.Node
instances:In generally, use
Y.one
andY.all
to rerun aY.Node
andY.NodeList
instance respectively; this is how you will see YUI 3 code written, and what all the examples will use.For your specific use case of wanting to remove a DOM element which you already hold a reference to you could do the following using YUI 3’s
Y.Node
class: