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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:15:24+00:00 2026-05-17T03:15:24+00:00

Assuming there is a mousestop event attached to the entire document, what is the

  • 0

Assuming there is a mousestop event attached to the entire document, what is the best way to figure out the exact word under the cursor (if there is any text), when the mouse stops moving?

I can get the underlying (jQuery) element from the event handler – $(document.elementFromPoint(e.clientX, e.clientY)) – but then what is next?

So far my idea is to replace all text nodes within hit element with their copy where each word is wrapped in a DOM element (don’t know which one yet) and then call $(document.elementFromPoint(e.clientX, e.clientY)) again to get the element that contains only the word under mouse.
But that seems like a complicated plan and I wonder whether I am missing something simpler.

  • 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-17T03:15:24+00:00Added an answer on May 17, 2026 at 3:15 am

    Well, no magic tricks so far, so here is the dull boring (and yet working) solution:

      $(document.body).mousemove(function(e){
    
        var onmousestop = function() {
          function getHitWord(hit_elem) {
            var hit_word = '';
            hit_elem = $(hit_elem);
    
            //text contents of hit element
            var text_nodes = hit_elem.contents().filter(function(){
              return this.nodeType == Node.TEXT_NODE && this.nodeValue.match(/[a-zA-Z]{2,}/)
            });
    
            //bunch of text under cursor? break it into words
            if (text_nodes.length > 0) {
              var original_content = hit_elem.clone();
    
              //wrap every word in every node in a dom element
              text_nodes.replaceWith(function(i) {
                return $(this).text().replace(/([a-zA-Z-]*)/g, "<word>$1</word>")
              });
    
              //get the exact word under cursor
              var hit_word_elem = document.elementFromPoint(e.clientX, e.clientY);
    
              if (hit_word_elem.nodeName != 'WORD') {
                console.log("missed!");
              }
              else  {
                hit_word = $(hit_word_elem).text();
                console.log("got it: "+hit_word);
              }
    
              hit_elem.replaceWith(original_content);
            }
    
            return hit_word;
          }
    
          var hit_word = getHitWord(document.elementFromPoint(e.clientX, e.clientY));
          ...
        }
      }
    

    There are few other subtleties involved (like event ‘noise reduction’, keeping replaced dom context (such as selection) and so forth), but you get the idea.

    Here you can learn how set up mousestop event.

    EDIT:

    Making custom html elements may not be that strait forward in IE (who would have thought?). Check out more here.

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

Sidebar

Related Questions

Is there any way to achieve a += operator within the css operator (assuming
Are there any way to access or set iphone's alarm? Im assuming if this
I am assuming there is a way to have this sub in? I am
Just a question about best-practices when upgrading an existing database. Assuming there will be
I have been trying to figure out if there are any differences between these
Easy question for you vets out there: What is the accepted (assuming there is
I am pretty new to AS, and I am assuming there is a way
Writing some test cases and my mind wanders, assuming there is a better way
I'm assuming there is an easy way to do this, but I think that
Assuming there are 5 inputs in web form <input name='the_same[]' value='different' /> <input name='the_same[]'

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.