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

  • SEARCH
  • Home
  • 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 7964183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:49:18+00:00 2026-06-04T05:49:18+00:00

I’m using mouseenter and mouseleave events in jquery on an unordered list’s <li> to

  • 0

I’m using mouseenter and mouseleave events in jquery on an unordered list’s <li> to show some image when the mouse goes over them. Here’s what that list typically looks like:

<ul class="myTree">
    <li class="treeItem" catid="1" catname="Category 1">
        <img src="img/fleche_hori.png" class="expandImage"/>
        Category 1
        <img src="img/cross.png" class="hidden removecategory"/>
        <ul>
            <li class="treeItem" catid="2" catname="Subcategory 1 1">
                <img src="img/spacer.gif" class="expandImage"/>
                Subcategory 1 1
                <img src="img/cross.png" class="hidden removecategory"/>
            </li>
            <li class="treeItem" catid="3" catname="Subcategory 1 2">
                <img src="img/spacer.gif" class="expandImage"/>
                Subcategory 1 2
                <img src="img/cross.png" class="hidden removecategory"/>
            </li>
        </ul>
    </li>
    <li class="treeItem" catid="4" catname="Category 2">
        ...
    </li>
</ul>

NOTE: I know it can be hard to read but I tried my best to make it as readable as possible.

So as you can see it’s merely a tree used for an expand/collapse tree, each item being marked with class “treeItem”. I need this class to stay and as it’s a common class shared by all these items that need to show an image when mouse goes over them, I decided to bind my event handler to it.

The image that needs to be showed/hidden on mouseenter/mouseleave is the second of each item (the one with src=”img/cross.png”). I managed to that quite easily with this script:

$(document).on("mouseenter", ".treeItem", function (e) {
    //e.stopPropagation();
    $(this).children(".removecategory").show();
});

$(document).on("mouseleave", ".treeItem", function (e) {
    //e.stopPropagation();
    $(this).children(".removecategory").hide();
});

My problem though is that when an item is expanded (i.e. “Category 1” is expanded and “Subcategory 1 1” and “Subcategory 1 2” are now shown) and I hover any of the sub-categories with my mouse, these subcategories’ images will be shown as asked but the parent category’s (i.e. “Category 1”) image won’t hide as I’m still hovering it as well…

I tried using e.stopPropagation(); but it didn’t do anything better..

Anyone knows a way to go around this and sort of trigger mouseleave on an element when I’m hovering some of its content ?

You can check http://api.jquery.com/mouseleave/#example-0 and especially the demo below the code block to see what I mean. Typically (on the right side of the demo) I would like that blue container’s mouseleave event is triggered when mouse enters yellow container.

I hope my question is clear because it was hard to explain…


EDIT:

I found a way modifying my mouseenter event handler to this:

$(document).on("mouseenter", ".treeItem", function (e) {
    $('.removecategory').each(function() {
        $(this).hide();
    });
    $(this).children(".removecategory").show();
});

but that isn’t perfect as I need to leave the entire parent item (i.e. “Category 1” item) and re-enter it to have the image shown again after hovering subitems.

If anyone has a better way please share!

  • 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-04T05:49:19+00:00Added an answer on June 4, 2026 at 5:49 am

    add span to each category and subcategory:

    <ul class="myTree">
        <li class="treeItem" catid="1" catname="Category 1">
            <img src="img/fleche_hori.png" class="expandImage"/>
            <span class="Item">Category 1</span>
            <img src="http://www.pokerland-il.com/images/smilies/smile.png" class="hidden removecategory"/>
            <ul>
                <li class="treeItem" catid="2" catname="Subcategory 1 1">
                    <img src="" class="expandImage"/>
                    <span class="Item">Subcategory 1 1</span>
                    <img src="http://www.pokerland-il.com/images/smilies/smile.png" class="hidden removecategory"/>
                </li>
                <li class="treeItem" catid="3" catname="Subcategory 1 2">
                    <img src="img/spacer.gif" class="expandImage"/>
                    <span class="Item">Subcategory 1 2</span>
                    <img src="http://www.pokerland-il.com/images/smilies/smile.png" class="hidden removecategory"/>
                </li>
            </ul>
        </li>
        <li class="treeItem" catid="4" catname="Category 2">
            ...
        </li>
    </ul>​
    

    change your JS to this:

    $('.Item').mouseover(function(){
        $(this).next(".removecategory").show();
    });
    
    $('.Item').mouseout(function(){
        $(this).next(".removecategory").hide();
    });​
    

    http://jsfiddle.net/xBwyZ/3/

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

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.