Category tree

Create a category tree where each category may have multiple nested categories.


  • Generate the category tree using the provided categories data. The provided code shows the expected HTML structure.
  • All categories should be expanded by default.
  • The toggle button should collapse or expand the category.
  • If the category is expanded, change the button text from - to +.
  • If expanding the category, always expand its children.
    For example:
    • collapse "Computers"
    • collapse "Electronics"
    • expand "Electronics"
    In this case "Computers" should also be expanded.
  • Add proper test attributes to category <li> elements. If the category id is 4, set data-test="category-4". Refer to the provided html code.
  • Try to keep the same HTML structure.

You are free to add classes, styles, ids, but don't edit or remove data-test attributes.
Create an account to start coding
Create account