Jquery: Hide all children, then show a specific element

function subDisplay(name) {
   $("#navSub").hide();
   $('#'+name).show();
}

To summarize the great comments from @dotweb and @Matt;

function subDisplay(name) {
   $('#navSub').hide();
   $(name).show();
}

subDisplay('#DivIwantToShow');

You need to hide the children and not the containing div.

$("#navSub").children().hide();

So now if the div you are trying to show is an element in the parent div it will still show while the others stay hidden.


If you're targeting the children of #navSub, you need target them and hide them, rather than the element navSub; which you can do using the children() method;

function subDisplay(name) {
    $('#navSub').children().hide();
    $(name).show();
};

Otherwise, it appears you have multiple elements with the same ID in your DOM, which is not allowed.

You then need to pass a string (which is a valid jQuery selector) to subDisplay();

subDisplay('#DivIwantToShow');