Advertisement
Guest User

Untitled

a guest
Sep 26th, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // The minimal changes version, but beware this only works on the *first* matching element
  2. var dropdownElement = document.getElementsByClassName(
  3.     "filter-multi-select-dropdown filter-panel-item-dropdown dropdown-menu show"
  4. );
  5.  
  6. document.addEventListener("click", (event) => {
  7.     const firstMatchingElement = dropdownElement[0];
  8.     if (event.target == firstMatchingElement) {
  9.         firstMatchingElement.classList.remove("show");
  10.         console.log("Clicked Outside");
  11.     }
  12. });
  13.  
  14. // Or alternatively, just check the target when the click happens
  15. // Note that unlike the above, this will work on *any* matching element
  16.  
  17. document.addEventListener("click", (event) => {
  18.     if (event.target.matches(".filter-multi-select-dropdown.filter-panel-item-dropdown.dropdown-menu.show")) {
  19.         event.target.classList.remove("show");
  20.         console.log("Clicked Outside");
  21.     }
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement