1

First off:
Sorry for my bad English and sorry if this question has already been answered (I feel that it should had) but ive been looking like a mad man but then again I also lack the proper English terms to locate the right question/answers :|

In any case, to the problem:
I need to (using javascript/*monkey) locate: a name="JustDoIT" and from that position 'back-step' to an div ID or Class and remove it.

Example: html -> body -> div.main -> div#textRNG -> div.static -> a[name:JustDoIT]

Where 'div#textRNG' is the DIV i want to delete but can't specifically target because 'RNG' keeps changing.

Dealing with the 'a' tag is not enough.

Ive been thinking of doing a loop going through all the div#textRNG then div.static to reach the a tag but this route is a lot more intensive and demanding than just finding the right a tag from the start and take two steps and delete the right div.

That's if it's even possible.

I appreciate all help with this!

EDIT

  • Just plain javascript if possible
  • Clarification: I need to remove (grandparent?) DIV based on content inside the 'A tag' inside the same tree(?)
SmitHan
  • 25
  • 5
  • Possible duplicate of [How to use greasemonkey to selectively remove content from a website](http://stackoverflow.com/questions/9169032/how-to-use-greasemonkey-to-selectively-remove-content-from-a-website) – wOxxOm Nov 26 '15 at 13:15
  • is there no way in regular javascript ? if possible id like to avoid getting jquery involved. also this seems to handle the same type of tags.. not different ones.. – SmitHan Nov 26 '15 at 13:28
  • 1
    `[].forEach.call(document.querySelectorAll("a[name='JustDoIT']"), function(node) { node.parentNode.parentNode.remove() });`, the inner code may be also `node.closest("div[id^='text']").remove()` – wOxxOm Nov 26 '15 at 13:52
  • Thanks! That's much more in the right direction however I can't get greasemonkey to play ball. I'm gonna read up more on greasemonkey and if I cant get it running ill just create a full example if you're ok with helping me out with it. – SmitHan Nov 26 '15 at 14:39

1 Answers1

1

If your code only needs to run on a recent version of Firefox/Greasemonkey you can use:

var objA = document.querySelector("a[name='JustDoIT']");
objA.parentNode.parentNode.remove();

However if you need backwards compatibility to older/other browsers, you need:

var objA = document.querySelector("a[name='JustDoIT']");
var grandParent = objA.parentNode.parentNode;
grandParent.parentNode.removeChild(grandParent);

References:

https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild

Lil Devil
  • 663
  • 5
  • 10
  • thank you so much for this and for including the example with older/other browsers, without that i would most likely still be banging my head against the wall - now I just have to create a timer or something because script is triggered before the page has finished loading the items so they're still visible, i experimented with "run-at document-end/idle" but that didnt seem to do anything for me here, but again thank you! i'd +1 you if i could :( – SmitHan Nov 27 '15 at 22:43