Hide a DIV which has no class/id

百般思念 提交于 2020-01-07 09:54:23

问题


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?


回答1:


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();



回答2:


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.




回答3:


$("div")
    .contents()
    .filter(function() {
         return this.text() == "text here";
})
  .hide();



回答4:


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/




回答5:


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).




回答6:


You can use:

div {
    display:none;
}

But this will hide all divs.

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



来源:https://stackoverflow.com/questions/19146313/hide-a-div-which-has-no-class-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!