You need to attach an event receiver to those elements a
and then use the .parentNode
to know what the element is li
you seek.
You’re gonna have to call .parentNode
that li
because the javascript API needs to know father and son: elementoPai.removeChild(filho);
.
That is to say:
var links = document.querySelectorAll('a');
for (var i = 0; i<links.length; i++){
links[i].addEventListener('click', removerPai);
}
function removerPai(e){
e.preventDefault();
var li = this.parentNode;
li.parentNode.removeChild(li);
}
var links = document.querySelectorAll('a');
for (var i = 0; i<links.length; i++){
links[i].addEventListener('click', removerPai);
}
function removerPai(e){
e.preventDefault();
var li = this.parentNode;
li.parentNode.removeChild(li);
}
<ul>
<li>
<a href="#">example</a>
</li>
<li>
<a href="#">example</a>
</li>
</ul>