Answer the question
In order to leave comments, you need to log in
How to hide child element under parent?
There is such a piece of layout on the page.
<a href="#" class="earn-item__control-item earn-item__control-item-fav earn-item__control-item_favorites">
<svg class="icon icon-star-empty"><use xlink:href="/images/icons/symbol-defs.svg#icon-star-empty"></use></svg>
</a>
(function () {
document.addEventListener("DOMContentLoaded", function (event) {
var favItems = [].slice.call(document.querySelectorAll(".earn-item__control-item-fav"));
favItems.forEach(function (elem) {
elem.addEventListener("click", function (event) {
var target = event.target;
event.preventDefault();
console.log(target);
});
});
});
}());
Answer the question
In order to leave comments, you need to log in
use parentNode or parentElement
elem.addEventListener("click", function (event) {
var target = event.target;
event.preventDefault();
console.log(target.parentNode); // <-- выводим в консоль предка с помощью parentNode
});
You already have the a tag in the closure:
(function () {
document.addEventListener("DOMContentLoaded", function (event) {
var favItems = [].slice.call(document.querySelectorAll(".earn-item__control-item-fav"));
favItems.forEach(function (elem) {
elem.addEventListener("click", function (event) {
console.log(elem);
});
});
});
}());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question