-2

Is it possible to hide a div with no class/id via css, or javascript? There is a possibility another div like this to be in the page.

<div align="center">text here</div>

Actually, it is an ebay listing template, and the software that will be used adds this div at the bottom with javascript and flash gallery in it and I that is why I want to hide that thing.

The div is between 2 comments:

<!--GalleryShowcaseFlash-->
<div align="center">text here</div>
<!--EndOfGalleryShowcaseFlash-->

Can these comments help to be removed the div between them with javascript?

ajp15243
  • 7,704
  • 1
  • 32
  • 38
a.m
  • 169
  • 3
  • 11
  • 1
    how would you identify this div, is something there that makes it different from other – Sachin Oct 02 '13 at 20:34
  • yes, `div { display: none; }` will do this (but it will hide ALL divs that do not have an explicitly set `display` property with higher specificity). if you show us the complete HTML markup, we may be able to select only the div in question using psuedoclasses. – Ennui Oct 02 '13 at 20:37
  • 1
    Do you have something against Id's? – eidsonator Oct 02 '13 at 20:38
  • You can only do it if something else about the `
    ` uniquely identifies it (since that's what you use classes and ids for). These other identifiers, as others have mentioned here and here, include its location in your markup and the ancestor elements of it (allowing the use of a specific selector in CSS/JS), the other attributes (such as your `align` attribute) on it (again for a CSS/JS selector), or the content inside of it (which will require JS to determine and use). Honestly, unless you don't have control over the markup or something, you should use a class/id.
    – ajp15243 Oct 02 '13 at 20:43
  • Since you've now let us know the `
    ` is between two comment elements, you might be able to select one of the specific comments with the help of [this jQuery comment plugin](http://www.bennadel.com/blog/1563-jQuery-Comments-Plug-in-To-Access-HTML-Comments-For-DOM-Templating.htm) (and filtering on comment text content), and then selecting that element's next (or prev) sibling, which will be that `
    `. Found the plugin link via [this question](http://stackoverflow.com/questions/1623734/selecting-html-comments-with-jquery).
    – ajp15243 Oct 02 '13 at 21:01

6 Answers6

5

There's not much we can go off here to be specific, you should really add a class or ID. Without that, it'd have to be something like:

div[align="center"] {
    display: none;
}

As for that text selector though, it's not possible in CSS

If it was jQuery, we could be a bit more specific and do

$("div[align='center']:contains('text here')").hide();
Community
  • 1
  • 1
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
3

Yes, you can style it via pseudo selectors such as nth child (if you know the position where that div falls), or by the attributes on that div.

Conqueror
  • 4,265
  • 7
  • 35
  • 41
3
$("div")
    .contents()
    .filter(function() {
         return this.text() == "text here";
})
  .hide();
DevlshOne
  • 8,357
  • 1
  • 29
  • 37
3

This CSS will hide all DIVs which has no ID or Class:

div {display:none}
div[class], div[id] {display:block;}

You go it working here: http://jsfiddle.net/heQjm/

2

It might be possible if some parent or sibling has a known class or ID. With JavaScript you could track that parent/sibling element and follow the trail from there.

But generally speaking you would be at the mercy of the elements (so to speak).

Sébastien
  • 11,860
  • 11
  • 58
  • 78
0

You can use:

div {
    display:none;
}

But this will hide all divs.

You can check here: http://jsfiddle.net/5r4TD/

Tiago
  • 358
  • 2
  • 14