javascript - Hiding an unordered list when it has no elements -
i have problem seems @ first total no-brainer , easy task.
i have javascript plugin on page generates table of contents list sidebar of wordpress pages. purpose hide text widget element of #toc when list within has no elements. i'm trying solve using jquery no luck.
the html:
<div class="textwidget"> <div id="toc"> <ul></ul> </div> </div> the javascript:
jquery(document).ready(function ($) { if (!$('#toc').children('ul').has('li')) { $('#toc').parent().hide(); } }); my script should hide specific #toc's parent, because has no child <li> elements, doesn't. instead, when remove ! if sentence, script hides list, if had in it. hides lists have elements in them. totally missing here?
simply use this:
$(document).ready(function () { if ($('#toc ul li').length < 1) { $('#toc').parent().hide(); } });
Comments
Post a Comment