Topic: Is there a way to load SideNav UL content dynamically? Using $("# list").html(list); The content loads but does not open on click.

marcos-queiroz free asked 5 years ago


https://mdbootstrap.com/snippets/jquery/marcos-queiroz-2/1375379?action=forum_snippet


Piotr Glejzer staff commented 5 years ago

Hi,

what a problem with this snippet?


marcos-queiroz free commented 5 years ago

when loading SideNav items dynamically, Collapse no longer worked.

Just add $ (". Button-collapse"). SideNav (); it went back to normal.


Piotr Glejzer staff commented 5 years ago

Yes, it will not work. The reason is that you create a new list and add this after the page is loaded. This collapsible function is a good workaround about that.


marcos-queiroz free commented 5 years ago

What would be the best solution?


Piotr Glejzer staff commented 5 years ago

Your solution is fine. You have to invoke the function again if you put that HTML code. You can use ES6+ syntax with template strings and const/let to do this.

I changed a little code and added an if statement to show you that if your list has a child with class collapsible then run this function again.

https://mdbootstrap.com/snippets/jquery/piotr-glejzer/1398042


marcos-queiroz free commented 5 years ago

Thank you, much more elegant.


Piotr Glejzer staff commented 5 years ago

You are welcome. Have a nice day.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.11
  • Device: All
  • Browser: All
  • OS: All
  • Provided sample code: No
  • Provided link: Yes