OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

active class with bootstrap sidebar

  • Thread starter Thread starter user8830601
  • Start date Start date
U

user8830601

Guest
The sidebar needs to change active class after click.This is my bootstrap code and i tried it with this javascript code but it doesn't works.


Code:
$(function(){
    $('.sidebar1 a').filter(function(){return this.href==location.href}).parent().addClass('active').siblings().removeClass('active')
    $('.sidebar1 a').click(function(){
        $(this).parent().addClass('active').siblings().removeClass('active')	
    })
})

Code:
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="sidebar">
    <div class="list-group">
         <ul class="siderbar1">
              <li><a href="HhwController" class="list-group-item active">Hoe het werkt</a></li>
              <li><a href="OveronsController" class="list-group-item">Over ons</a></li>
             <li><a href="VpController" class="list-group-item">Veiligheid en privacy</a></li>
             <li><a href="FAQController" class="list-group-item">FAQ</a></li>
              <li><a href="Contactform" class="list-group-item">Contact</a></li>
          </ul>
     </div>
 </div>
<p>The sidebar needs to change active class after click.This is my bootstrap code and i tried it with this javascript code but it doesn't works.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$(function(){
$('.sidebar1 a').filter(function(){return this.href==location.href}).parent().addClass('active').siblings().removeClass('active')
$('.sidebar1 a').click(function(){
$(this).parent().addClass('active').siblings().removeClass('active')
})
})</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="sidebar">
<div class="list-group">
<ul class="siderbar1">
<li><a href="HhwController" class="list-group-item active">Hoe het werkt</a></li>
<li><a href="OveronsController" class="list-group-item">Over ons</a></li>
<li><a href="VpController" class="list-group-item">Veiligheid en privacy</a></li>
<li><a href="FAQController" class="list-group-item">FAQ</a></li>
<li><a href="Contactform" class="list-group-item">Contact</a></li>
</ul>
</div>
</div></code></pre>
</div>
</div>
</p>
Continue reading...
 
Top