Skip to content

Instantly share code, notes, and snippets.

@Gergling
Created July 30, 2014 11:42
Show Gist options
  • Save Gergling/35e457a28bb75b4845d0 to your computer and use it in GitHub Desktop.
Save Gergling/35e457a28bb75b4845d0 to your computer and use it in GitHub Desktop.
DOM Element Click Toggle
/* Stolen from anonymous234 on http://what.thedailywtf.com/ (http://what.thedailywtf.com/t/banners-that-change-as-you-scroll-down-the-page-and-dont-have-a-close-button/1754/48) */
/* Run to activate remove-clickable elements */
/* Run again to switch off */
javascript:var b=new Array();var c=1;var o=((document.onkeydown==null)||(o==2))?0:1;document.onkeydown=ck;z=document.getElementsByTagName('*');for(i=0;i<z.length;i++){if(z[i].tagName.search(/(HTML|BODY)/i)==-1){z[i].onclick=function(e){t=this;if(window.event) e=window.event;if((t==e.target)||(window.event)) t.parentNode.removeChild(t);e.stopPropagation();return false;};z[i].onmouseover=function(){if(!c)return;c=0;t=this;b[t]=t.style.backgroundColor;t.style.background='#FF9999';};void(z[i].onmouseout=function(){t=this;t.style.backgroundColor=b[t];c=1;});}}function ck(e){k=window.event?window.event.keyCode:e.keyCode;if((k==27)||o){o=2;document.onkeydown=null;for(i=0;i<z.length;i++){if(z[i].tagName.search(/(HTML|BODY)/i)==-1){z[i].onclick=null;z[i].onmouseover=null;z[i].onmouseout=null;z[i].style.backgroundColor=b[t];}}}}if(o==1) ck(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment