Reputation: 555
i am using vuejs to drag/drop elements, and basicly i am using the evt.to and evt.from to know if i am dragging the element to the list2 for example, this evt.to/from returns me the html tree from my draggable element that has the list, so the parent has the id="list2" if i drag it to there, i need to know how i can track if my evt.to has the list2 element with plain javascript or maybe vueJS
tried this:
if(evt.to.getElementById("list2")){
console.log("IT HAS");
}
i don't want to check on all document, just on that evt.to, how can i do that without Jquery ?
Upvotes: 0
Views: 4530
Reputation: 326
I'm not sure what exactly is inside the evt.to variable but you should be able to just do this:
evt.to.id
Upvotes: 0
Reputation: 1075467
Assuming evt.to
is a DOM element:
If you want to know if evt.to
itself has the id
, you can use its id
property:
if (evt.to.id == "list2") {
// Yes, it is it
}
If you need to see if it contains an element with that ID, you could use querySelector
on it:
if (evt.to.querySelector("#list2") != null) {
// Yes, it has it
}
If you need to allow for both, that's easily done:
if (evt.to.id == "list2" || evt.to.querySelector("#list2") != null) {
// Yes, it is it or has it
}
Upvotes: 3