3

Here is the JsFiddle

I have a css rule depending on the display status of a neighbor:

#top:not([style*="display: none"]) + #bottom {
  color:red;
}

When I hide the '#top' div using javascript, the color changes since the css rule is no longer valid. This is not the case in Internet Explorer and Edge ! Am I doing something wrong or is this just a bug in Microsofts browsers ?

Aaqib
  • 9,942
  • 4
  • 21
  • 30
Yalla T.
  • 3,707
  • 3
  • 23
  • 36

1 Answers1

1

I would avoid that approach, as it's somewhat fragile. Instead, explicitly toggle a class on a parent element or #top, and make your CSS changes based on that:

body.toggled #bottom {
  color:red;
}
body.toggled #top {
  display: none;
}

$("#btn").click(function() {
  $('body').toggleClass('toggled');
});

Demo

isherwood
  • 58,414
  • 16
  • 114
  • 157