Skip to content
Advertisement

How to get ul inside an li

JavaScript

This li item is generated dynamically I want to toggle li on the cate-label button click. for that, I did the following code

JavaScript

when I try to hide item using ItemToHide.find(“.sub-cate”).hide(); it didn’t hide anything . I tried to find the length of the item using ItemToHide.find(“.sub-cate”).length but it returned 0.

Advertisement

Answer

Lower your event handling to something closer. I wrapped everything in a <menu> tag and registered the click event to it instead of document. It doesn’t make much of a difference performance wise but I suggest it because it’s looks as if your perspective is skewed if dealing with a larger view of the DOM and you’ll be error prone:

JavaScript

That nightmare is now:

JavaScript

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement