1

if we have this structure, how can hide the #div if the button is focused

before I used to do it using the selector ~ like that but now it didn't work out

    button:focused ~ #div{
       display: none;
    }
<div id="div">This is a normal div</div>
  <div class="container">
      <button type="button" class="button">Click me</button>
  </div>
Aditya Thakur
  • 2,199
  • 1
  • 6
  • 19

1 Answers1

1

button:focus + #div{
display: none;
}
<div class="container">
    <button type="button" class="button">Click me</button>
    <div id="div">This is a normal div</div>
</div>

Check this out

DAMMAK
  • 141
  • 11
  • this is working only if the div is beside the button, what about if the div is beside the container of the div, like the code shown in the example above? – Yassine Safraoui May 15 '19 at 18:49