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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:54:21+00:00 2026-06-04T10:54:21+00:00

I have a DIV representing a BLUE rectangle with text HELLO that, when user

  • 0

I have a DIV representing a BLUE rectangle with text “HELLO” that, when user clicks on it changes its colour to RED and text “BYE”, and when user moves mouse cursor out, restores its original colour and text. These styles are described in CSS, and text is controlled from GWT Events (see Java code below).

The issue is that, when I move the mouse very fast, the ONMOUSEOUT event is not fired in any browser. But works fine if I move it slowly.

Any ideas, please? THANKS

MyFile.html

<div id="boxDiv" class="myStyle"></div>

MyFile.java

final Element boxDiv = DOM.getElementById("boxDiv");
DOM.sinkEvents((com.google.gwt.user.client.Element)boxDiv,Event.ONCLICK | Event.ONMOUSEOUT);
DOM.setEventListener((com.google.gwt.user.client.Element)boxDiv,new EventListener(){
    public void onBrowserEvent(Event e) { 
        Element targetDiv = DOM.eventGetTarget(e);
        switch (DOM.eventGetType(e)) {
      case Event.ONCLICK: onClickHandler(e, targetDiv); break;
          case Event.ONMOUSEOUT: onMouseOutHandler(e, targetDiv); break;
    }
}
  • 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-04T10:54:23+00:00Added an answer on June 4, 2026 at 10:54 am

    EDIT

    Given your modified question and the added complexity of changing text, let’s use GWT as GWT is awesome for this kind of thing!

    Ok, first our very simple CSS stylesheet:

    .myStyle {
    background-color: blue;
    }
    
    .myStyle-clicked {
    background-color: red;
    }
    

    Here a very basic Widget that does pretty much exactly what you asked (sorry for changing the text, I tested this and I’m sure it will always work even when moving the mouse extremely fast) in beautiful, simple Java (GWT) code:

    private class MyWidget extends Composite {
    
        private Label label = new Label();
        private static final String originalText = "Hello world!";
        private static final String clickedText = "Goodbye world!";
    
        public MyWidget() {
            sinkEvents(Event.ONCLICK | Event.ONMOUSEOUT);
            label.setText(originalText);
            initWidget(label);
            setStyleName("myStyle");
        }
    
        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            switch (event.getTypeInt()) {
            case Event.ONCLICK:
                addStyleDependentName("clicked");
                label.setText(clickedText);
                break;
            case Event.ONMOUSEOUT:
                removeStyleDependentName("clicked");
                label.setText(originalText);
                break;
            }
        }
    
    }
    

    OLD ANSWER IF YOU ARE JUST WORRIED ABOUT MOUSE_OVER AND MOUSE_OUT

    The solution to this problem is to stop doing this programmatically and do it using the native browser’s events handling system, which is as fast as you can get.

    To do this, use the CSS hover filter. For clicking, you don’t need to worry, your problem is just move-in and move-out, which as you found out, are cases where you may not be able to trust the JS to handle very well.
    I think all browsers currently support this:

    <!DOCTYPE html>
    
    <html>
      <head>
       <style>
        .tt {
           background-color: blue;
        }
        .tt:hover {
           background-color: red;
        }
       </style>
      </head>
      <body>
        <div class="tt">
            The content of the body element is displayed in your browser.
        </div>
      </body>
    </html>
    

    I tested this and it works in Chrome, FF and IE9. According to ther w3schools docs, it works also in Safari and Opera.

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

Sidebar

Related Questions

I have div tag, I have a free text(on its own) in that tag.
I have a div with a width of 200px. There is text inside that
It seems that in Firefox, if I have div A with fixed width/height and
I have navigation menu that once the user click then change and fade the
jQuery 1.7.1, jQuery UI tabs. I have the following HTML representing tabs, <div id=tabs>
I have div containing multiple divs and text. The inner divs are alternately floated
I have div that I display dynamically when certain conditions arise. When I display
I have div of fixed width containing only input text box and width of
I have div that goes in to an edit mode... the div contains buttons,
I have div that contains 2 divs in it. One of the child divs

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.