0

How i can add the checkbox and label css click event inside a DIV? the below codes not works for me, if i remove "" its working perfect. Why is happening?


HTML

<div id="wrapper">
       <input name="" type="checkbox" value="" id="hub" class="hub"  style="display:none;"/>
       <label for="hub"  class="hub2"></label>
    </div>

    <div class="slide"> 
       the contents
    </div>

CSS

.slide{
    background:red; 
}


input[type=checkbox].hub:checked ~ .slide {
    background:green !important;    
}
1
  • 1
    .hub and .slide are not in the same node, ~ is for siblings Commented Jun 9, 2013 at 7:34

1 Answer 1

2

You must put your .slide element along with the label and the input[type=checkbox], like following

<div id="wrapper">
   <input name="" type="checkbox" value="" id="hub" class="hub"  style="display:none;"/>
   <label for="hub"  class="hub2">open</label>
   <div class="slide"> 
      the contents
   </div>
</div>

Demo

More on sibling selector

Sign up to request clarification or add additional context in comments.

1 Comment

without js no, you cannot, the css selector only allow children or descendent siblings

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.