there's also Element.closest which can be super helpful when you need to know if there's an element in the tree above the one you're querying with.
e.g.
functionhandleClick(event){constheader=event.target.closest('.accordion-header');constaccordion=event.target.closest('.accordion');constbody=accordion?.closest('.accordion-body');if(header){// if I've clicked inside of the header// toggle the display of the body of the accordionbody.hidden=!body.hidden;}}document.documentElement.addEventListener('click',handleClick,true);
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
there's also
Element.closestwhich can be super helpful when you need to know if there's an element in the tree above the one you're querying with.e.g.