The problem is that the browser window just hangs when executing js code more than a few times.

var getNoHide = dcm.querySelectorAll('[click-nohide]'), setHide = dcm.querySelectorAll('[hide]'); Array.prototype.forEach.call(setHide, function(setHide) { setHide.style.display="none"; }); function click_hide(){ click_nohide = Array.prototype.forEach.call(getNoHide, function(getNoHide) { var value = getNoHide.getAttribute('click-nohide'), getIdHide = dcm.getElementById(value); getNoHide.style.cursor="pointer"; getNoHide.addEventListener('click', function(){ getNoHide.removeAttribute('click-nohide'); getNoHide.setAttribute('click-hide', value); getIdHide.style.display="block"; getNoHide.addEventListener('click', function(){ getNoHide.removeAttribute('click-hide'); getNoHide.setAttribute('click-nohide', value); getIdHide.style.display="none"; return click_hide(); }); }); }); } click_hide(); 

Update

It should hide / show on click items with a selector.

 function click_nohide(){ Array.prototype.some.call(getNoHide, function(getNoHide) { var value = getNoHide.getAttribute('click-nohide'), getIdHide = dcm.getElementById(value); getNoHide.style.cursor="pointer"; getNoHide.onclick = function(){ getIdHide.style.display="block"; getNoHide.removeAttribute('click-nohide'); getNoHide.setAttribute('click-hide', value); getHide = dcm.querySelectorAll('[click-hide]'); click_hide(); }; }); } click_nohide(); //click-nohide function click_hide(){ Array.prototype.some.call(getHide, function(getHide) { var value = getHide.getAttribute('click-hide'), getIdHide = dcm.getElementById(value); getHide.style.cursor="pointer"; getHide.onclick = function(){ getIdHide.style.display="none"; getHide.removeAttribute('click-hide'); getHide.setAttribute('click-nohide', value); click_nohide(); }; }); } click_hide(); }; 

So, if.

  • 2
    oh-wei, my eyes, where to hang so many identical click handlers? Yes, and constantly call them from each other? Every call to getNoHide.addEventListener('click', adds handler - Grundy
  • one
    Well, it is worth adding a description, what does this code have to do? - Grundy
  • one
    forEach is a method that returns nothing , so there is no point in doing click_nohide = Array.prototype.forEach.call (...) click_nohide variable - always will be undefined - Grundy

0