delete a whole <div id="fobbar"> pane?

2,727 views
Skip to first unread message

Ben Stover

unread,
Apr 4, 2012, 3:35:26 AM4/4/12
to Greasemonkey Users
How can I delete a whole <div> pane with the following spec:

<div id="foobar">
....
</div>

Ben


Tei

unread,
Apr 4, 2012, 3:48:07 AM4/4/12
to greasemon...@googlegroups.com
With JQuery is easy
$("#foobar").remove();

Withouth JQuery... you could, maybe, find the parent of the node, is
index, and make parent.childNode[index] = null; Side effect of this
is that deleting a huge tree this way is instant. Other option is to
use a function to delete all childrens with parent.removeChild ...


About JQuery,... hee... JQuery is a higuer level of abstraction that
pure Javascript. Is like a new programming language that compile to
javascript. By being a few orders of magniture more abstract than pure
javascript, solutions are easier to write, and the intention of the
code is obvious. The only downside is having to download this 200KB
library, but a greasemonkey will have that cached. I can't imagine
cases where somebody can't use JQuery, the other 99.99% of the
javascript programmers have not reason to use naked javascript. JQuery
is the new Javascript.

...And sorry about that, because this fact hurt these people that
don't want or can't use JQuery, and that make me sad :(

> --
> You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
> To post to this group, send email to greasemon...@googlegroups.com.
> To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
>

--
--
ℱin del ℳensaje.

Klaus Johannes Rusch

unread,
Apr 4, 2012, 4:07:36 AM4/4/12
to greasemon...@googlegroups.com
On 04.04.2012 09:48, Tei wrote:
> ...And sorry about that, because this fact hurt these people that
> don't want or can't use JQuery, and that make me sad :(
:-)

jQuery is indeed nice, in combination with Greasemonkey I only ran into
problems with one site that was using $ for another library and had
scripts active while Greasemonkey kicked in, and before I could undo
jQuery's taking over $. The workaround for that was a patched jQuery
library that doesn't set $ and voilà, works there too.

--
Klaus Johannes Rusch
klaus...@atmedia.net
http://klausrusch.atmedia.net/

Michal Wojciechowski

unread,
Apr 4, 2012, 1:17:28 PM4/4/12
to greasemon...@googlegroups.com

Try this:

var elem = document.getElementById("foobar");
elem.parentNode.removeChild(elem);

--
Michal Wojciechowski
http://odyniec.net/ | http://userscripts.org/users/49673

Ben

unread,
Apr 5, 2012, 9:24:30 AM4/5/12
to greasemon...@googlegroups.com
Is this JQuery code or does it require any other library to load in advance?
 
Or can I simply put your code into a GM *.user.js script?

Michal Wojciechowski

unread,
Apr 5, 2012, 10:00:37 AM4/5/12
to greasemon...@googlegroups.com
On 04/05/2012 03:24 PM, Ben wrote:

> Is this JQuery code or does it require any other library to load in advance?
>
> Or can I simply put your code into a GM *.user.js script?

It's plain DOM code, so it does not require any libraries. You can put
it in your script as it is.

mike cupcake

unread,
May 17, 2012, 8:04:17 AM5/17/12
to greasemon...@googlegroups.com
if simply hiding it from view would be acceptable, an alternative method uses CSS:

GM_addStyle("#foobar { display: none !important; } ");

Anthony Lieuallen

unread,
May 17, 2012, 11:02:27 AM5/17/12
to greasemon...@googlegroups.com
Much better:

document.getElementById('foobar').style.display = 'none';

mike cupcake

unread,
May 18, 2012, 8:02:41 AM5/18/12
to greasemon...@googlegroups.com
On Thursday, May 17, 2012 4:02:27 PM UTC+1, Anthony Lieuallen wrote:
Much better:

document.getElementById('foobar').style.display = 'none';

That'll work in other software besides Greasemonkey (I think?),  what else makes it better?  If there's more than one style to change GM_addStyle seems less cluttered,   and won't this method fail if the element is created after the script has run..?
Reply all
Reply to author
Forward
0 new messages