Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

make navigation open when items are 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 :: eva icons js 
Javascript :: convert javascript to java 
Javascript :: axios params onclick function 
Javascript :: mantine progress 
Javascript :: weakset use cases 
Javascript :: what is container in angular 
Javascript :: javascript pad 
Javascript :: Compiled with problems:X ERROR [eslint] Plugin "react" was conflicted between 
Javascript :: javascript create li element and append to ul 
Javascript :: react component lifecycle 
Javascript :: prisma.db firebase 
Javascript :: req.session undefined express node js 
Javascript :: array inside array javascript 
Javascript :: how to square number in javascript 
Javascript :: pencil button in react 
Javascript :: modify an array in javascript using function method 
Javascript :: express roteamento 
Javascript :: Execercise for loop 
Javascript :: how to get the first element in an array in javascript 
Javascript :: desync resolver 
Javascript :: js draw number in range 
Javascript :: node js knex sqlite query 
Javascript :: json to list react 
Javascript :: add flag persmison to write file nodejs 
Javascript :: angularjs Add aria-label to table header in datatable 
Javascript :: Angular.js : recursive call to an $mdDialog controller 
Javascript :: React Native Swift Escaping closure 
Javascript :: arrow function - one line and no parameters 
Javascript :: How can I configure multiple sub domains in Express.js or Connect.js 
Javascript :: Javascript array of array loop 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =