How to Change Style of Parent
  • on Hover

  • Tags: jquery,css,wordpress-theming

    Problem :

    I have a WordPress site (on my localhost) that uses a <ul> for a custom menu. How can I change the CSS of a <li> on hover only if it has a <ul> sub-menu?

    All the main menu items have a border-radius and I want to remove this on the current item (Services, below) for example:

        <div class="main-nav">
          <ul class="menu" id="menu-main-nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">Services</a>
              <ul class="sub-menu">
                <li><a href="#">Item One</a></li>
                <li><a href="#>Item Two</a></li>
              </ul>
            </li>
            <li><a href="#>Contact</a></li>
          </ul>
        </div>
    

    I can't find a CSS solution and I've tried jQuery too:

        $('ul.sub-menu').parent().hover(function(){
        $(this).addClass('no-radius');
    }); 
    


    Solution :

    $('.menu li').has('ul').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    

      CSS Howto..

      How to style a png icon with CSS?

      How to make css border shape [duplicate]

      how to set zoom level using css

      CSS: How to increase distance between two elements?

      How to control multiple images for a single background definition

      How to have multiple CSS transitions on an element?

      How to change the font-size of the part of textarea text in HTML,CSS?

      How to add percentage-of-height top/bottom margin in CSS

      How can I put a div block below another lined up vertically when they are touch and are on the same line?

      How to apply global styles with CSS modules in a react app?

      How to avoid display block for a particular div element using css

      CSS: How does setting a right margin cause the element's parent to become visible in this example?

      How to add space between elements (but not outside of them) using CSS?

      how to make a CSS animation end point the right edge of the browser

      How can I get this style effectv with css or jquery?

      How can I move a div with direction in JavaScript?

      How to share CSS StyleSheet amongst projects?

      how to get fixed table columns width

      CSS: show only the last x items in a list

      How to select loose text between tags

      How do I control the height of the main content area no matter how much text is in there?

      How can I animate my div to go from top to bottom whithout interfering with the content inside?

      How to include materialize-css npm package with webpack

      How to add CSS to an if else statement in PHP

      CSS: How to add classes to existing grid that allow skipping columns on the left side

      How load a table into multiple webpages using HTML?

      How are media queries counted in IE's CSS selectors limit?

      How to build a complex table by using CSS?

      How to dynamically change the style of a comma separated tags with html/css/jquery

      How can I force a css flex child to be the only on its row?