Skip to content

Instantly share code, notes, and snippets.

@ahmadmysra
Forked from agibsonsw/hide_element
Created April 29, 2018 00:20
Show Gist options
  • Save ahmadmysra/d1b7e339d72b1710ef104f7df83798e4 to your computer and use it in GitHub Desktop.
Save ahmadmysra/d1b7e339d72b1710ef104f7df83798e4 to your computer and use it in GitHub Desktop.
JS Bookmarklet to hide an element on click
javascript:(function(){var%20d=document,useMine=true,prevEl;function%20AddHandler(orig,mine)
{return%20function(e){if(useMine)mine(e);else%20if(orig)orig(e);};}function%20Myonmouseover(e)
{var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.outline='2px%20solid%20gray';
prevEl=elem;}function%20Myonmouseout(e){var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.outline='';}
function%20Myonclick(e){var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.display='none';}
function%20Myonkeydown(e){var%20evt=e||window.event;if(evt.keyCode==27){prevEl.style.outline='';useMine=false;}}
d.onmouseover=AddHandler(d.onmouseover,Myonmouseover);d.onmouseout=AddHandler(d.onmouseout,Myonmouseout);
d.onclick=AddHandler(d.onclick,Myonclick);d.onkeydown=AddHandler(d.onkeydown,Myonkeydown);})()
@ahmadmysra
Copy link
Author

ahmadmysra commented Apr 29, 2018

# agibsonsw commented on Feb 5, 2012

This is a bookmarklet I crafted so that I can click elements, images, on a web page to hide them.Create a Bookmark and paste the code as the property for the bookmark. Add it as a button on your bookmarks toolbar. If you want to hide something, click the button. As you point around the page a grey box outlines what you will (try) to hide. You can continue clicking, then press Escape to finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment