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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:24:02+00:00 2026-06-04T15:24:02+00:00

Using JQuery I am trying to chain a couple of functions when an element

  • 0

Using JQuery I am trying to chain a couple of functions when an element has a hover state.

I would normally use the .hover event function, but after reading some tutorials I read that using .on is better as you can use one event handler to monitor all bubbling events within a document.

However, I am having problems when I chain two functions together like so:

$("element").on( "hover", function() {         
    console.log("one");     
}, function() {         
    console.log("two");     
});

I expected the result to be one two (which was the case when using .hover) but instead I get two two.

Can anyone explain what I am doing wrong or whether this is expected behaviour and why?

Reproduced using .hover(...): http://jsfiddle.net/gXSdG/

Reproduced using .on(hover...): http://jsfiddle.net/gXSdG/1/

  • 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-04T15:24:04+00:00Added an answer on June 4, 2026 at 3:24 pm

    .on() can only take 1 function, so you have to interrogate the passed event to check what the event was. Try this:

    $("element").on("hover", function(e) {
        if (e.type == "mouseenter") {
            console.log("one");   
        }
        else { // mouseleave
            console.log("two");   
        }
    });
    

    Example fiddle

    Alternatively you can split the two events which constitute the hover() method – mouseenter and mouseleave:

    $("#element").on("mouseenter", function() {
      console.log("one");   
    }).on('mouseleave', function() {
      console.log("two");   
    });
    #element {
      background-color: black;
      height: 100px;
      margin: 100px;
      width: 100px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="element"></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JQuery and trying to use delegate for the hover action. Problem is
I'm trying to make simple script using jquery $post function to pass data to
i'm trying to submit my Ajax form using jQuery. However calling the submit() function
using jQuery i am trying to find out all the URLS that user has
Using jQuery, I'm trying to change the selected option in a SELECT element to
Using jQuery 1.7.1, I'm trying to create an event handler for the change event
I am trying to submit a form using jQuery's .ajax() function. It seems like
Using JQuery, I'm trying to set an option as selected in a 'select' element
Currently Im trying to do ajax request using jQuery Mobile. I`m trying to use
I am trying to return an error using jquery post function to retrieve the

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.