0

If I have a page that inserts an unwanted div on every load, is there any way to hide it without using CSS? I don't have access to that div and it doesn't have an ID or a CLASS.

For example I don't want the browser to display the following div:

<div style="text-align: center; font-size: 14px; text-decoration: none;">Please click <a style="text-decoration: none !important;" target="_blank" href="http://www.website.com"><b>here</b></a></div>

I found a question and an answer for hiding a specific string of text, but it doesn't work with this.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Andrei P
  • 1
  • 1
  • 2
  • 2
    Depending on the HTML hierarchy you can hide it with CSS or JavaScript. – j08691 Nov 07 '14 at 15:10
  • 1
    It's possible, you don't have access to the source code to prevent it appearing that way? If not, can you post the content around the div? i.e. what are its parent elements? – Stu Nov 07 '14 at 15:10
  • There must be something to identify the div with, be it content, be it parents etc...You can target anything but we need more info. – somethinghere Nov 07 '14 at 15:11
  • Sounds like you're trying to hide some sort of copyright notice and/or ad on a page? If so, while its possible, tread carefully as you might be breaking some sort of EULA. – charles Nov 07 '14 at 15:20
  • Is the link anchor a known URL? if so, I would target with that as the selector (see: http://stackoverflow.com/a/303961/1981678) and work up to the parent and then do a .remove() with jQuery to get the div gone – BReal14 Nov 07 '14 at 15:28
  • If you can't touch the HTML and get rid of the div, how are you going to add a script to do it (which is what you need)? – Tim Nov 07 '14 at 15:28

3 Answers3

0

You can do

 document.getElementsByTagName("div")[0].style.display = 'none';
vmontanheiro
  • 1,009
  • 9
  • 12
0

You can try to select content inside the div by using attribute value. Href attribute inside your div is perfect to do this, and then just use jQuery .parent() method to select whole div.

$("a[href='http://www.website.com']").parent().css("display","none")

Here is the working example:

http://jsfiddle.net/waxtue0o/

Marian Gibala
  • 874
  • 7
  • 9
0

There are some ways of identifying an element without it having an id or class. If you have jquery you can use more advanced selectors like mgibala said (although I would prefer to do it without scripting).

See http://www.w3schools.com/cssref/css_selectors.asp for information on selectors. Two examples below.

Fiddle: http://jsfiddle.net/o8oyd3e2/

HTML:

<body>
    <div style="background-color='red';">
        Spam spam spam
    </div>
    <div>
        Some content
    </div>
    <div class="myContent">
        Some content
    </div>
    <div style="background-color='red';">
        Spam spam spam
    </div>
</body>

CSS:

body div:first-child {
    display:none;
}

body div.myContent + div {
    display:none;
}

Or you can host your site somewhere else...

Anananasu
  • 70
  • 6