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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:13:37+00:00 2026-06-18T22:13:37+00:00

Fiddle What I have now is almost good, but when you move the mouse

  • 0

Fiddle

What I have now is almost good, but when you move the mouse along a table row, the button gets removed for some reason, which I don’t want. I only what the button to be removed if you mouseout of the whole table.

HTML: Looks like any old table with 3 columns and 12 rows + a <thead> with 3 columns.

JS:

$(document).ready(function(){
    $('#editData tr').hover(function(){
        $('button').remove();
        $(this).children('td:last-child').append('<button id="editButton">Edit</button>');
    });
    $('#editData').mouseout(function(){
        $('button').remove();
    });
});

CSS:

#editData {
  width: 500px;
  margin: auto;
  background: #dadce1;
  margin-bottom: 50px;
  box-shadow: 0 0 10px 1px #e1e1e1;
}
#editData tbody {
  border: 1px solid #b8b8b8;
  border-top: 0;
}
#editData thead {
  border: 1px solid #b8b8b8;
  border-bottom: 0;
  background: rgba(255,255,255,0.7);
  font-size: 20px;
}
#editData thead th {
  padding: 10px;
  font-weight: bold;
  text-align: center;
}
#editData th:last-child, #editData tr td:last-child {
  width: 40px;
}
#editData tr {
  text-align: center;
  height: 30px;
}
#editData td {
  padding: 3px;
}
#editData tr:nth-child(even) {
  background: rgba(255,255,255,0.7);
}
#editButton {
  width: 40px;
  height: 24px;
  border-radius: 5px;
  padding: 0;
}
  • 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-18T22:13:39+00:00Added an answer on June 18, 2026 at 10:13 pm

    Using the second parameter .hover. This will attach a mouseleave handler to your rows (tr).

    $('#editData tr').hover(function(){
        $(this).children('td:last-child').append('<button id="editButton">Edit</button>');
    }, function() {
        $('button').remove();
    });
    

    Fiddle

    Basically, just balanced your mouseenter and mouseleave handlers for the rows.


    Also if you’re interested in knowing the real issue, read about mouseout vs mouseleave (demo at bottom of the page).

    The problem is, mouseout bubbles up so every time it fires in any descendant of the table, it will bubble up to the table element and trigger its mouseout handler.

    From the mouseout docs:

    This event type can cause many headaches due to event bubbling. For instance, when the mouse pointer moves out of the Inner element in this example, a mouseout event will be sent to that, then trickle up to Outer. This can trigger the bound mouseout handler at inopportune times. See the discussion for .mouseleave() for a useful alternative.


    hover is just a shorthand that attaches mouseenter and mouseleave handlers, you could explicitly use mouseleave instead of mouseout in your original example and it’d work as well:

    $('#editData tr').mouseenter(function(){
        $('button').remove();
        $(this).children('td:last-child').append('<button id="editButton">Edit</button>');
    });
    $('#editData').mouseleave(function(){
        $('button').remove();
    });
    

    Fiddle

    This second piece of code is what you asked for: it removes all buttons when you mouseleave the table, while the first is my refactored version that appends a button when you mouseenter the row and removes it when you mouseleave it. Both have the same visible effect.


    Side-note: I’ve replaced the hover by mouseenter in the example as .hover would unnecessarily attach the handler to both mouseenter and mouseleave events when called with a single argument.

    With .hover, the mouseleave for the tr would remove the button and create a new one and, when you move the mouse to outside the table, the event would bubble up to the table element removing the just-created button, or if you move the mouse to another row, the handler would also be called twice (mouseleave of old row and mouseenter of the new hover target row). Of course this is not visible as these handlers would execute in microseconds and browsers may group up repaints. You can see that it is what actually happens with some console.logs in this fiddle.

    This may not make much difference in this use-case (except performance) but in many other cases you may run into issues – many questions on SO are because questioners thought that .hover() called with a single argument would attach solely a mouseenter handler which is not the case.

    ps. I aimed this answer at your event bubbling/logic problem, but you don’t have to abuse jQuery for something as simple as that. @Daryl Ginn’s answer is a very suitable solution for real-world use. =]

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

Sidebar

Related Questions

see fiddle i have html table and one textbox and one button.make cell selection
I have a form that creates inputs in a table row. I have now
JSfiddle: http://jsfiddle.net/ybZvv/57/ I have a fiddle here where the user can append row and
I have created table as create table tab (id int, mytext varchar(200)); Now I
I have this fiddle: http://jsfiddle.net/y9mhE/3/ Now I want to make the canvas control fit
I have a button nicely lined up with an input box in this fiddle
I have a javascript creating a list. All works, see my fiddle: http://jsfiddle.net/mauricederegt/mjdyW/4/ Now
I have a script that works for the slider. But now I need to
This is the code I have right now with jQuery. 1.fiddle. What I want
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1

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.