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 7681375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:19:38+00:00 2026-05-31T18:19:38+00:00

I have a <ul> that is populated with javascript after the initial page load.

  • 0

I have a <ul> that is populated with javascript after the initial page load. I’m currently using .bind with mouseover and mouseout.

The project just updated to jQuery 1.7 so I have the option to use .on, but I can’t seem to get it to work with hover. Is it possible to use .on with hover?

EDIT: The elements I’m binding to are loaded with javascript after the document loads. That’s why I’m using on and not just hover.

  • 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-05-31T18:19:39+00:00Added an answer on May 31, 2026 at 6:19 pm

    (Look at the last edit in this answer if you need to use .on() with elements populated with JavaScript)

    Use this for elements that are not populated using JavaScript:

    $(".selector").on("mouseover", function () {
        //stuff to do on mouseover
    });
    

    .hover() has its own handler: http://api.jquery.com/hover/

    If you want to do multiple things, chain them in the .on() handler like so:

    $(".selector").on({
        mouseenter: function () {
            //stuff to do on mouse enter
        },
        mouseleave: function () {
            //stuff to do on mouse leave
        }
    });
    

    According to the answers provided below you can use hover with .on(), but:

    Although strongly discouraged for new code, you may see the
    pseudo-event-name "hover" used as a shorthand for the string
    "mouseenter mouseleave". It attaches a single event handler for those
    two events, and the handler must examine event.type to determine
    whether the event is mouseenter or mouseleave. Do not confuse the
    "hover" pseudo-event-name with the .hover() method, which accepts one
    or two functions.

    Also, there are no performance advantages to using it and it’s more bulky than just using mouseenter or mouseleave. The answer I provided requires less code and is the proper way to achieve something like this.

    EDIT

    It’s been a while since this question was answered and it seems to have gained some traction. The above code still stands, but I did want to add something to my original answer.

    While I prefer using mouseenter and mouseleave (helps me understand whats going on in the code) with .on() it is just the same as writing the following with hover()

    $(".selector").hover(function () {
        //stuff to do on mouse enter
    }, 
    function () {
        //stuff to do on mouse leave
    });
    

    Since the original question did ask how they could properly use on() with hover(), I thought I would correct the usage of on() and didn’t find it necessary to add the hover() code at the time.

    EDIT DECEMBER 11, 2012

    Some new answers provided below detail how .on() should work if the div in question is populated using JavaScript. For example, let’s say you populate a div using jQuery’s .load() event, like so:

    (function ($) {
        //append div to document body
        $('<div class="selector">Test</div>').appendTo(document.body);
    }(jQuery));
    

    The above code for .on() would not stand. Instead, you should modify your code slightly, like this:

    $(document).on({
        mouseenter: function () {
            //stuff to do on mouse enter
        },
        mouseleave: function () {
            //stuff to do on mouse leave
        }
    }, ".selector"); //pass the element as an argument to .on
    

    This code will work for an element populated with JavaScript after a .load() event has happened. Just change your argument to the appropriate selector.

    EDIT JAN 2023

    I know this is an older one but I thought id share this as it confused me a little bit, was going around in circles. But I applied the domsubtreemodifer logic that you have to target the wrapper.

    Im unsure if jquery has changed over time but, You also have to include the container now that you are adding the target to.

    So for example:

    Your dom looks like this:

    <div class="taggable">
    </div>
    

    Your adding a div like so in jquery

    $('.taggable').append('<div class="close"><div>');
    

    Your DOM will end up looking like this.

    <div class="taggable">
       <div class="close"></div>
    </div>
    

    So in order for you mouse event to work you need to target the container AS well as the element you have added

    $(document).on({
        mouseenter: function () {
        },
        mouseleave: function () {
        }
    }, ".taggable .close"); 
    
    $(function () {
      $('.taggable').append('<div class="close">testme<div>');
    });
    
    
        $(document).on({
            mouseenter: function () {
            console.log('mouseenter');
            },
            mouseleave: function () {
            console.log('mouseleave');
            }
        }, ".taggable .close"); 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <div class="taggable">
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that is populated using an XML file. However, I want
I have a data table that is initially empty and is populated after a
I have a site that I am currently working on in ASP.NET 2.0 using
I have a javascript array that is dynamically populated. Example: Array name $testarr[] And
I have a div on my page that gets populated via an ajax call
I have a radajaxpanel that is populated with the selected item from a combobox
I have a select that gets populated depending on the selection in a different
I have an NSMutableArray that is populated with objects of strings. For simplicity sake
I have a TableModel that is populated from a background running thread. I am
I have an NSTableView that contains a few columns that are populated with data.

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.