1

I am trying to make a CSS style for a website However in their HTML they do not use IDs for containers. Some of these containers have adverts, while others do not. I want to display:none the containers adverts. The adverts themselves have IDs, and so does the normal content.

This is what their HTML looks like:

<div id="wrapper">

    <div class="container">
        <div id="advert"> Advert </div>
    </div>

    <div class="container">
        <div id="content"> Normal stuff </div>
    </div>

    <div class="container">
        <div id="advert2"> Advert </div>
    </div>

</div>

1 Answers1

1

What you are referring to is selecting the ID's Parent in the DOM structure. You cannot do this with CSS at the moment but with CSS4 there should be a way to select a parent in the DOM. At the moment is is done with JQuery. To get the parent div for the 'advert' ID would be...

$( "#advert" ).parent().css( "display", "none" );
Derrick Wells
  • 218
  • 1
  • 11
  • This won't work because this will only apply to 1 advert and not all. If you notice there is an `id="advert2"` – Adjit Jan 05 '15 at 19:51
  • Then you do it again for that ID.. he didnt ask how to do it for all.. just how to select a parent in the DOM. If he wants to do it for all just make all the ID's into an Array and use a simple for loop to cycle through all of them. – Derrick Wells Jan 05 '15 at 20:08
  • Thanks for answering quickly! Unfortunately I am unable to use anything but CSS, but thanks anyway. – Herossaumure Jan 05 '15 at 21:15