Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

keep nav open when child item is active

$('.nav-item li a').each(function() {
    if ($(this).hasClass('active')) {
      	$(this).parents("ul").css('display', 'block');
    }
})

//ex.
//html
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
	<li class="nav-item nav-parent">
        <a href="#" class="nav-link nav-link-parent">
      		<i class="fa-solid fa-file-lines"></i>
            <p class="nav-title">Parent</p>
		</a>
        <ul class="nav nav-treeview">
            <li class="nav-item">
                <a href="#" class="nav-link">
                    <p>Child</p>
                </a>
            </li>
		</ul>
	</li>
</ul>

//js
$(document).ready(function() {
	$('.nav-treeview li a').each(function() {
        if ($(this).hasClass('active')) {
            //show children
            $(this).parents("ul").css('display', 'block');
            //open nav-parent
            $(this).closest(".nav-parent").addClass('menu-open');
            //add class active in nav-parent-link
            $(this).closest(".nav-parent").find(".nav-link-parent").addClass('active')
        }
   	})
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react axios request data objest from online json with table element 
Javascript :: javascript destructure multiple levels 
Javascript :: Add Click events to multiple classes. 
Javascript :: tiled spatialmaterial godot 
Javascript :: ticket draw 
Javascript :: disable submit button until form is fully validated 
Javascript :: loading local csv file using d3.csv 
Javascript :: netsuite get search column value suitescript 
Javascript :: convert snake case to camelcase javascript recursive 
Javascript :: javascript load on error 
Javascript :: what happens if pass argument to a function that does not have parameters javascript 
Javascript :: broken image 
Javascript :: js two operations in ternary 
Javascript :: auto refresh vue pwa 
Javascript :: javascript chicken 
Javascript :: prisma.db yaml 
Javascript :: starting: intent error type 3 react-native 
Javascript :: nested object 
Javascript :: page object 
Javascript :: delete file firebase angular 
Javascript :: Ajax in wordpredss 
Javascript :: add decimal places to number javascript 
Javascript :: useMediaquery hook react 
Javascript :: js delete without changing index 
Javascript :: absolute item onPress ToucableOpacity problem 
Javascript :: javascript Change color based on a keys value in each object of array 
Javascript :: AngularJS Graphs & Charts - Mix of solid & dotted 
Javascript :: How to set up path paramater in angular and access in the controller 
Javascript :: Angular Nx Nrwl - Cannot parse tsconfig.base.json: PropertyNameExpected in JSON when try to create a new lib 
Javascript :: wrapping a span tag with an a tag with a href target same as the text of the span 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =