Ad

Bootstrap Nav Collapse Via Data Attributes Not Working

- 1 answer

I'm trying to get a Twitter Bootstrap 3 navbar to collapse via data attributes but it's not expanding.

For reference, the project is an ASP.NET C# MVC project running DNN (DotNetNuke) CMS.

When manually calling the collapse method via javascript it works fine for example:

$('#main-menu').collapse()

This leads me to believe that the javascript files are fine and something's wrong with the data attributes. I've compared every element to a working example and cannot see what's causing the issue. Here's the complied HTML:

<nav class="navbar navbar-default navbar-style">
    <div class="container-fluid">
        <div class="navbar-header">
            <button class="navbar-toggle collapsed" data-target="#main-menu-collapse" data-toggle="collaspe" aria-expanded="false">
                <span class="sr-only">Toggle Navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse" id="main-menu-collapse">
            <ul class="nav navbar-nav">
                <li><a target="_blank" rel="nofollow noreferrer" href="http://localhost:801/">Home</a></li>
                <li class="dropdown">
                    <a target="_blank" rel="nofollow noreferrer" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">BG New Page <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a target="_blank" rel="nofollow noreferrer" href="http://localhost:801/BG-New-Page/Some-Page">Some Page</a></li>
                        <li><a target="_blank" rel="nofollow noreferrer" href="http://localhost:801/BG-New-Page/Some-More-Context">Some More Context</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

FWIW, removing the navbar-style class makes no difference.

Ad

Answer

Change data-toggle="collaspe" to data-toggle="collapse".

Ad
source: stackoverflow.com
Ad