Skip to content
Advertisement

Can I target a specific Flexbox container and fill it with the contents of another file?

I am looking for a way to dynamically populate a submenu depending on the selection of the main menu, then, when a user clicks on an item in the submenu, it populates two flexboxes with the contents of another file. I can’t figure out how to target a flexbox using JS; or, if that’s not possible, what I could do instead. For example:

JavaScript

FLEXBOX CONTAINERS:

JavaScript

Is this possible? What should I search to figure it out? I have Googled to no avail, I’m not searching for the right phrase. What should I be looking for?

Advertisement

Answer

Here is one possible implementation. You add an event listener on each trigger element—in my case, a button. When the button is clicked, you target the .flex element adjacent to the button and dynamically insert HTML content.

JavaScript
JavaScript
JavaScript

jsFiddle

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