M
M
mangust17852021-07-01 14:59:55
css
mangust1785, 2021-07-01 14:59:55

How to determine with js that an element is active?

Hello!

$(document).mouseup(function (e){ // событие клика по веб-документу
  var divmenu = $("#sidepanel"); // sidebar
  if (!divmenu.is(e.target) && divmenu.has(e.target).length === 0) { // если клик был не по нашему блоку и не по его дочерним элементам
    enableScroll();
    $('#sidepanel_btn').css("pointer-events", 'auto');
  }
});


This function listens for a click outside of the element (sidebar)
How can I make this function only fire when the sidebar is active/open? Otherwise, it catches click events, including when the sidebar is closed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-07-01
@mangust1785

$(document).mouseup(function (e){ // событие клика по веб-документу
  var divmenu = $("#sidepanel"); // sidebar

  if (!divmenu.is(e.target) && divmenu.has(e.target).length === 0 && divmenu.hasClass("active") ) { // если клик был не по нашему блоку и не по его дочерним элементам
    enableScroll();
    $('#sidepanel_btn').css("pointer-events", 'auto');
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question