-3

I want to hide external div If it will have an image with specific class. For example

<div class="slide">
  <img class="hidden" src="">
<div>
<div class="slide">
  <img class="shown" src="">
<div>

I want to hide div only that has hidden class.

Tomasz Mularczyk
  • 27,156
  • 17
  • 99
  • 146
wpdd
  • 363
  • 2
  • 10
  • You should give us an example of what you tried so we have a point of reference and also to help others if they have similar issues. – zfrisch Feb 02 '18 at 17:35
  • 1
    CSS has no parent selector so you can't do anything to an ancestor element based on a descendant element, so you'd need a JavaScript solution. Please show us what you've tried. – j08691 Feb 02 '18 at 17:36
  • Next time please take care with the tags. If you allow JS then https://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector is no longer a duplicate – mplungjan Feb 02 '18 at 17:53

1 Answers1

1

If you are using jQuery you can do the following:

$(function() {
     $(‘.hidden’).parent().hide()
})

The middle line selects the parent of the DOM element and hides it. Wrapping the code within an anonymous function wrapped within the jQuery function delays execution of the code until the DOM is ready to be manipulated.

Neil Girardi
  • 3,608
  • 1
  • 22
  • 30