Greetings and thank you for visiting!
I am reaching out to seek your expertise in resolving a problem that seems straightforward but has been challenging :(
Currently, I am working on developing a website with a large collapsing menu (similar to a sitemap) that is visually appealing but impractical for mobile views. As a solution, I have created an additional menu specifically designed for display on mobile devices and smaller screens.
The summarized code structure looks like this:
<nav class="navbar navbar-light bg-light ">
<div class="container-fluid ">
<a class="navbar-brand" href="index.php" id="btnLogo">
<img src="../images/logo.png" width="130" height="80" class="d-inline-block align-top" alt="logo">
</a>
<button class="navbar-toggler navbar-toggler-right float-right"
type="button"
data-toggle="collapse"
data-target="#desktopMenu"
aria-controls="desktopMenu"
aria-expanded="false">
<span>MENU</span>
<span class="navbar-toggler-icon"></span>
</button>
<!-- Desktop Menu Section -->
<div id="desktopMenu" class="collapse navbar-collapse">...</div>
<!-- Mobile Menu Section -->
<div id="mobileMenu" class="collapse navbar-collapse">...</div>
My question is: Is there a way to dynamically change the "data-target" and "aria-controls" attributes to switch between "desktopMenu" and "mobileMenu" based on the viewport width?
I am unsure if this approach is optimal. Please feel free to suggest alternative methods if you believe there is a better way to achieve this functionality.
Thank you for your assistance!