Reputation: 33
I am trying to convert this jQuery code to vanilla js
$(".gone").click(function(){
$(this).hide();
});
any help?
Upvotes: 1
Views: 72
Reputation: 68933
You can try with querySelectorAll()
and forEach()
and addEventListener()
var gone = document.querySelectorAll(".gone")
Array.from(gone).forEach(function(g){
g.addEventListener("click", function(){
this.style.display = "none";
});
});
<div class="gone">Gone 1</div>
<div class="gone">Gone 2</div>
<div class="gone">Gone 3</div>
Upvotes: 2