How can I collapse a nested list using jQuery?

I have a nested list: ...and want to collapse the nested ul when the li is clicked. Before I was using $('UL LI').click(function(){ $(this).next().slideToggle(); }); ...but this obviously causes a problem when a li doesn't have a ul nested after it. Is there a better way to do this, or is there a way for me to determine if the object returned by $(this).next() is a UL?

以上就是How can I collapse a nested list using jQuery?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准