23 February 2023

How to Keep active navbar according to url in jQuery?

Stay active navbar according to url in jQuery


<script>

    /** add active class and stay opened when selected */

var url = window.location;


// for sidebar menu entirely but not cover treeview

$('ul.nav-sidebar a').filter(function() {

    return this.href == url;

}).addClass('active');


// for treeview

$('ul.nav-treeview a').filter(function() {

    return this.href == url;

}).parentsUntil(".nav-sidebar > .nav-treeview").addClass('menu-open').prev('a').addClass('active');

</script> 

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...