I have a div container that contains receptacle inputs for a form at the top. So I want the div hidden, id $('#sources').css('display','none')
However there is one div inside all of that which I want shown. Due to the irritating source files in a series of dynamically generated options in the source receptacles I cannot find a way of separating out the div I want shown from the rest as not everything has an ID.
Any ideas,
Marvellous
This is part of how HTML and CSS works. You cannot hide a parent element and still display a child element.
Perhaps you could try setting all child elements except that one to hidden.
Also, .hide()
is an easier shortcut for .css('display','none)
.
$('#sources').children(':not(#showThis)').hide()
No you need to place that div outside.
You have to move the div you want shown outside the div that's hidden. It's best, obviously, to do that in the markup. If you can't do that in the markup for some reason, you can do it afterward with jQuery:
var sources = $("#sources");
var target = sources.find("selector_for_the_target_div");
sources.hide();
target.insertBefore(sources);
That uses insertBefore
to move the target div outside the #sources
div. (I also used hide
, which is a shorter version of css('display', 'none')
.)
You could give this a shot:
`$('#sources').children().not("#div_you_want_to_show").css('display', 'none');