I need to toggle an icon inside the div element. The main issue for me is that toggling will happen everytime an user clicks on the div, not on the icon.
HTML
<div class="faq__questions-question" ><span>Lorem ipsum?</span><i class="fas fa-minus"></i></div>
What I've been tryin to do was adding onclick
event inside the icon or div but it works only on itself.
<i onclick="myFunction(this)" class="fas fa-minus"></i>
then my javascript is
function myFunction(x) {
x.classList.toggle("fa-plus");
}
How can I select only an icon class while clicking on the whole div? I think I'd need to use onclick event on the div:
<div onclick"myFunction()" class="faq__questions-question" ><span>Lorem ipsum?</span><i class="fas fa-minus"></i></div>
but what should I do to my javascript code?