How can I apply a style to a parent of a specific child

Niks

I've created a menu where if the user clicks on one of the side menu items then the side menu and the side menu children are all displayed, but the problem I have is that all my menu items are bold instead of the selected child and it's parent.

I hope I explained this clearly,

My HTML

<div id="second-menu" class="collapse navbar-collapse menu_two">
    <ul class="nav navbar-nav inside-nav">
        <li class="sub_menu">   
            <a href="#">Section 1</a>
            <ul class="sidenav_wrapper">
                <li class="sidenav_item sidenavlast">
                    <a href="#">Section 2</a>
                </li>
            </ul>
        </li>
        <li class="sub_menu">
            <a href="#">Section 3</a>
            <ul class="sidenav_wrapper">
                <li class="sidenav_item">
                    <a href="#">Section 4</a>
                </li>
                <li class="sidenav_active">
                    <a href="#">Section 5</a>
                </li>
                <li class="sidenav_item">   
                    <a href="#">Section 6</a>
                </li>
                <li class="sidenav_item sidenavlast">
                    <a href="#">Section 7</a>
                </li>
            </ul>
        </li>
        <li class="sub_menu">
            <a href="#">Section 8</a>
            <ul class="sidenav_wrapper">
                <li class="sidenav_item">
                    <a href="#">Section 9</a>
                </li>
                <li class="sidenav_item">
                    <a href="#">Section 10</a>
                </li>
                <li class="sidenav_item sidenavlast">
                    <a href="#">Section 11</a>
                </li>
            </ul>
        </li>
    </ul>
</div>

My JS

    $('ul.navbar-nav li').hover(

    function () {
        $(this).find('.sidenav_wrapper:first').css('display', 'block');
    },

    function () {
        $(this).find('.sidenav_wrapper:first').css('display', 'none');
    });


    $(".sidenav_active").parent().css({
        "display": "block"
    });


    if ($('.sidenav_active').length > 0) {
        $('.sidenav_wrapper').parent().find('a').css({
            "font-weight": "700"
        });
    }

My CSS

.menu_two {
    border-left: 16px solid #dfdfdf;
    padding-left: 0;
}
.sidenav_wrapper {
    background: none repeat scroll 0 0 #e7ecf5;
    border-left: 6px solid #8fb8e6;
    display: none;
    padding: 0;
}

.active_sub_menu a{
    font-weight: 700;
}

.active_sub_menu .sidenav_wrapper{
        display: block;
    }

.sidenav_active a{
        font-weight: 700;
    }

My jsfiddle: JSFIDDLE

Arun P Johny

I think what you need is

$('ul.navbar-nav li').hover(function () {
    $(this).find('.sidenav_wrapper:first').css('display', 'block');
}, function () {
    $(this).find('.sidenav_wrapper:first').css('display', 'none');
});

$(".sidenav_active").parent().css({
    "display": "block"
});

$('.sidenav_active').closest('.sub_menu').find('a').css({
    "font-weight": "700"
});

Demo: Fiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Apply parent style to specific child only

How can I apply styles from a parent component to a child component of the form <Child style={'border':'1px solid red'}

How to apply css style only for specific Vue component and its child?

How can i only apply styles to the parent element without change the childs style

Apply css style to child element of parent class

Apply style to parent if it has child with css

How can I change the style of a parent component?

How can I apply CSS to any div except those inside a parent div with a specific class?

How i can to move child dict to parent?

How can I display a specific child component inside a parent component with its own routing in Angular?

How can I exclude a specific child category post from a parent category?

How can I set a parent element's width to the width of a specific child

How can I, in Sass, target a specific child based on which parent it has, then use it inside media queries?

How can I get all parent keys given a specific child key in react native

How can I map/add field(s) from a node's parent into specific child leaves?

In django how can I loop through specific fields in the parent model (user) including some specific fields in the attached child model (userprofile)

How can set element alignment which is inside parent with the child style setting in element style attributes?

How can I apply a style using LESS to a nephew element of a class

How can I apply style to a div based on condition in thymeleaf?

How Can I apply CSS style to a selected row only?

How can I apply this style only on the first page?

How can I apply fallback style properties to a React JS component?

How can I apply style to a div based on condition?

How can I apply a style starting from the index of a NodeList?

How can I apply a CSS style to the whole row in a grid?

how can I apply css style to select focus?

How can I apply style based on a trigger property to a content control?

How can I apply seaborn.scatterplot(style) in matplotlib module?

How can I apply a style to the footer in Word 2010 with VBA?