window.onload = function(){ // When the page has finished loading. $(".nested").each(function(){ // Check every "nested" class if($(this).children().length == 0){ // If this nested class has no children $(this).hide(); // This will hide it, but not alter the layout // $(this).css("display", "none"); // This will alter the layout } else{ $(this).show(); //$(this).css("display", "none"); // This will alter the layout } }