twitter-bootstrap-3auto-closeiphone-8-plusiphone-8

Why is the vav auto close (Bootstrap) - Not working for the iPhone 8?


So when my webpage is viewed on mobile devices, the responsive nav menu auto closes when a link is selected in the drop down nav. Works fine on android and up to iPhone 6s. Just tested it on an iPhone 8 plus, but for some reason the auto close function does not work and it has to be closed manually. Any ideas on how to fix it?

//Javascript
//Auto-close responsive navbar after selection
    $('.navbar-collapse ul li a').click(function(){
      $('.navbar-toggle:visible').click();
    });

//HTML - using Bootstrap 3
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
      <div class="col-md-12">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </button>
          <a class="navbar-brand" href="#"><img src="img/logo_flat.png" class="img-responsive" style="width: 140px; margin-top: -16px;"></a>
        </div>
        <div class="collapse navbar-collapse navbar-right" id="myNavbar">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#banner">Home</a></li>
            <li class=""><a href="#aboutus">About Us</a></li>
            <li class=""><a href="#whatwedo">What We Do</a></li>
            <li class=""><a href="#faqs">FAQs</a></li>
            <li class=""><a href="#careers">Careers</a></li>
            <li class=""><a href="#contactus">Contact Us</a></li>
          </ul>
        </div>
      </div>
    </div>
  </nav>

Solution

  • Try this

    $('.navbar-collapse a').click(function(){
    $(".navbar-collapse").collapse('hide');
    });