If it has id , you can use document.getElementById :
var div = document.getElementById("alertPanel");
Then, if it exists, you can either remove it (possibly a bad idea) or hide it:
if (div) { div.style.display = "none"; // Hides it // Or // div.parentNode.removeChild(div); // Removes it entirely }
Refresh . Repeat your answer to another answer:
thanks for your reply. Your statemt applies to the page with iframes too. This question is in the iframe. I tried ypur solution and it didn't work. perhaps a link to the page will help: tennis.betfair.com the div I want to disable is the one that has id: minigamesContainer
If the element is in an iframe , then you should call getElementById in the document, which is in the iframe , since iframe are separate windows and have separate documents. If you know the id for the iframe , you can use document.getElementById to get the iframe instance, then use the contentDocument to access its document, and then use getElementById to get the "minigamesContainer":
var iframe, div; iframe = document.getElementById("the_iframe_id"); if (iframe) { try { div = iframe.contentDocument.getElementById("minigamesContainer"); if (div) { div.style.display = "none"; } } catch (e) { } }
( try/catch exists due to a potential security error accessing the contents of the iframe, I don’t know Greasemonkey well enough to find out if SOP applies to it. I am inclined to assume that this is not so, but it’s better safe ...)
If you don’t know the iframe id or if you don’t have one, you can just view all of them by getting their document.getElementsByTagName , and then the loop:
var iframes, index, iframe, div; iframes = document.getElementsByTagName("iframe"); for (index = 0; index < iframes.length; ++index) { iframe = iframes[index]; try { div = iframe.contentDocument.getElementById("minigamesContainer"); if (div) { div.style.display = "none"; break; } } catch (e) { } }
Literature: