Reputation: 101
I have something like:
<div id="id1">
//some code 1
<div id = "id2">
//some code 2
</div>
</div>
Now, I hide the all block with the command :
$("#id1").hide();
But, when I'm trying to show the inner block, with the command:
$("#id2").show();
But this doesn't work!
What should I do to fix this?
Upvotes: 0
Views: 105
Reputation: 6625
No this isn't possible using display:none
(which is what .hide()
does). display:none
hides the element, and thus any child elements will not be displayed.
This might be along the lines of what you want, if you're able to switch from using display
to visibility
.
#id1 {visibility: hidden;}
#id2 {visibility: visible;}
Check out the working fiddle: http://jsfiddle.net/vLYnk/2/
With javascript you could use:
$("#id1").css('visibility', 'hidden');
$("#id2").css('visibility', 'visible');
Upvotes: 1
Reputation: 48793
When parent element is hidden , all its children are hidden too.
If you want to show only the element with 'id2
' id, you can do it like this:
$('#id1').children(':not(#id2)').hide(); //Hiding all children except '#id2'
$('#id1').show();
Upvotes: 9
Reputation: 169
create an element and copy it then show it.
var element = jQuery('#id2').clone();
element.appendTo('some element');
Upvotes: 0
Reputation: 3109
you need to move the inner div out if you want to show it. somthing like
$("#id2").parents(":visible").appendTo($("#id2"))
Upvotes: -2
Reputation: 250842
If id1
is hidden, it doesn't matter whether id2
is visible or not. It won't be shown because its parent is hidden. This is true for all descendent elements.
Upvotes: 4