Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:27:57+00:00 2026-06-10T17:27:57+00:00

I have a nested html structure like this: <ul class=root> <li>Foo 1 <label class=bar-class>bar</label>

  • 0

I have a nested html structure like this:

<ul class="root">
    <li>Foo 1 <label class="bar-class">bar</label>
         <ul>
            <li>Foo 2 <label class="bar-class">bar</label>

            </li>

            <li>Foo 3 <label class="bar-class">bar</label>

            </li>
        </ul>
    </li>
</ul>

And so on, it is a site map so the nesting can be as deep as you like.

I am trying to show and hide the bar label on hover of the li element.

With code like this:

 $('.root li').live({
                mouseenter:
                       function () {
                           $(this).find('>.bar-class').show('slow');
                       },
                mouseleave:
                       function () {
                           $(this).find('>.bar-class').hide('fast');
                       }
            });

The problem is, that every li parent of the current also shows its bar, how do I select it so that ONLY the current item’s bar gets selected?

I’ve tried variations but just not cracked it yet.

Thanks.

Edit 1: Fixed html tags.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:27:59+00:00Added an answer on June 10, 2026 at 5:27 pm

    You can return false from the callback function to stop further propagation of the event up the DOM tree.

    And also change to using mouseover and mouseout:

    $('.bar-class').hide();
    
    $('.root li').live({
      mouseover:
        function () { $(this).find('>.bar-class').show('slow'); return false; },
      mouseout:
        function () { $(this).find('>.bar-class').hide('fast'); return false; }
    });​
    

    At this point I would like to encourage you to convert from using live to using on(), because live is deprecated.

    In this case, the code becomes:

    $('.root').on('mouseover mouseout', 'li', function () {
      $(this).children('.bar-class').stop(true, true).fadeToggle('slow');
      return false;
    });​
    

    Reference thanks to Yoshi: http://jsfiddle.net/6FzWU/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML structure: <div class=start> <div class=someclass> <div class=catchme> <div=nested> <div class=catchme>
I have a nested ul menu structure that starts off like this: <div id=left>
I have a nested model structure that looks like this: resources :users, :path =>
I have this structure models class Tournament < ActiveRecord::Base AGES = [5u, 6u, 7u,
So I have a nested div structure and I would like to get the
This is a JavaScript/Ajax webpage (also using jQuery). I have a nested structure I
I have this block of html: <div> <p>First, nested paragraph</p> </div> <p>First, non-nested paragraph.</p>
I have to create the following type of HTML structure: <div id=dcontent> <ul class=thm>
I have html nested like so <div id=content> <div id=asection> <h1>Some Text</h1> </div> </div>
Let's say I have a nested resource like in the Rails guide example: http://guides.rubyonrails.org/routing.html#nested-resources

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.