Search code examples
javascriptbookmarklet

How do I create a bookmarklet to hide a specific page element?


I'm a total noob with bookmarklets. Can anyone help me with the code I need to put in my bookmark URL to hide this specific page element?

<div id="snigel-cmp-framework" class="snigel-cmp-framework" style="height: 722px;">

Element I want to hide

It's for a website I access a lot with a super annoying/aggressive cookie policy. You have to click a million checkboxes to opt out, and your preferences are erased when you close your browser.

Thanks!


Solution

  • It's a simple javascript, you just need to make it a one liner, and addjavascript: as href of the link you shall drag to your bookmark bar to become bookmarklet. As for the code itself, it's pretty simple.

    <a href='javascript:var elem = document.querySelector("#snigel-cmp-framework"); elem && elem.remove()'>Drag me to bookmark bar</a>