Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a <ul> when only one element in the <ul> exists

Can someone tell me how to hide a <ul> when I only have one child <li> in it?

I have this code but it's not working.

$(document).ready(function() {
 $("#flex-slider-carousel ul li").length();
  if($('#flex-slider-carousel ul li').length == 1){
 $("#flex-slider-carousel ul li").hide();}
});

Thanks!

like image 315
Mel Avatar asked Dec 07 '25 03:12

Mel


1 Answers

length is a property not a method. You can use the filter method:

$("#flex-slider-carousel ul").filter(function() {
   return $(this).children().length === 1;
}).hide();
like image 123
undefined Avatar answered Dec 08 '25 17:12

undefined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!