I'd like to hide the second id
with value my2
via CSS:
<div class="node1">
<div class="xxx"> blablabla </div>
</div>
<div id="my2">
<div class="xxx"> blablalbla </div>
</div>
<div class="node2">
<div class="xxx"> blablabla </div>
</div>
<div id="my2">
<div class="xxx"> blablalbla </div>
</div>
Is it possible as to hide the second my2
div
?
E.g.
.node2 ? #my2 {
display:none;
}
Thank you!
Use the ~ selector in your CSS make the association. Then toggle the display between none and block . NOTE: You could use <div> instead of <a> for the buttons if you wish.
Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document. getElementById("element").
You can find <div> by id , look at it's style. display property and toggle it from none to block and vice versa.
The default display value for most elements is block or inline . This panel contains a <div> element, which is hidden by default ( display: none ). It is styled with CSS, and we use JavaScript to show it (change it to ( display: block ).
Yes possible:
Using
~
you can select all siblings with that class(id your case).
.node2 ~ #my2{
display:none;
}
You can also use
+
to select the immediate sibling.
.node2 + #my2{
display:none;
}
Hope it helps!
In order to target the #my2 element after .node2, you'll need to add a + sign between them.
.node2 + #my2 {
display: none;
}
But as mentioned before, using multiple id's is invalid markup.
this will hide #my2
which is right after .node2
.node2 + #my2{
display:none;
}
NOTE: dont use same id for multiple elements
Link each button
id
to each show
id
IE: #button1
links to #show1
. Use the ~
selector in your CSS make the association. Then toggle the display
between none
and block
.
Demo
HTML
<a id="button1">Button 1</a>
<a id="button2">Button 2</a>
<a id="button3">Button 3</a>
<div class="text">
<div class="hidden text" id="show1">This is 1</div>
<div class="hidden text" id="show2">This is 2</div>
<div class="hidden text" id="show3">This is 3</div>
</div>
CSS Use the ~
selector to reference each id
CSS
.hidden {
display: none;
}
#button1:hover ~ .text #show1 {
display: block;
}
#button2:hover ~ .text #show2{
display: block;
}
#button3:hover ~ .text #show3{
display: block
}
.text {
position: relative;
top: 10px;
}
NOTE: You could use <div>
instead of <a>
for the buttons if you wish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With