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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:45:57+00:00 2026-05-12T06:45:57+00:00

NOTE: Solved my own problem, it seems. See the edits. I am trying to

  • 0

NOTE: Solved my own problem, it seems. See the edits.

I am trying to write a greasemonkey script that will highlight all the matching texts on the page when the user selects a text, and then remove the highlighting when the selection is canceled. I am looking for a jQuery way to do this. It seems like there is a select event in the jQuery core, but I couldn’t get it to work they way I wanted it. Try running the following on this page for instance:

$(document).select(function () { 
      console.log("hey");
  });

There is no response. So it seems that I need to attach this to text nodes in particular. But that doesn’t seem practical to me. It would be way too slow.

Any suggestions, ideas? Thanks.

EDIT # 1:Ken Browning pointed out that the select event in jQuery only fires in textarea and input fields. So I guess I have to abandon that. Maybe I can change my question slightly, and ask if anyone can tell me the javascript way to bind selection events to all the text nodes.

EDIT # 2: I think I found part of my answer. This returns the selected text on the page, but you still have to click a button to show it. There is no select event binding. Hm.

<script language=javascript>
function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {//javascript select event
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
document.aform.selectedtext.value =  txt;
}
</script>
<input type="button" value="Get selection" onmousedown="getSelText()"> 

http://www.codetoad.com/javascript_get_selected_text.asp

EDIT # 3: SO I bound to the mouseup event rather than to selection. I am then checking the value of the getSelText() to proceed further after that point. Yay!

EDIT # 4: In case anyone is curious, I posted my finished script on Userscripts. Here is the link. Enjoy!

http://userscripts.org/scripts/show/55148

  • 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-12T06:45:58+00:00Added an answer on May 12, 2026 at 6:45 am

    In Firefox, document.getSelection() will return the selected text.

    You could attach an onmouseup handler to the document, and check for the selection each time you receive a mouseup event.

    Note: After I wrote this, you posted some source code to get the selection. While that code is fine (and cross-browser), if you’re using Greasemonkey you must be on Firefox, so all you need is document.getSelection().

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

Sidebar

Ask A Question

Stats

  • Questions 246k
  • Answers 246k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Watch your capitalization: private void printCollection(Collection collection) { for (Object… May 13, 2026 at 8:24 am
  • Editorial Team
    Editorial Team added an answer Something like: // Capture the wrapper template html var wrapper… May 13, 2026 at 8:24 am
  • Editorial Team
    Editorial Team added an answer Here's my workaround that's been working... function EnableChangeDetection(eForm) { //… May 13, 2026 at 8:24 am

Related Questions

I'm building a community-based site in Rails for the members of a real-world organization.
I am implementing URL rewriting in ASP.net and my URLs are causing me a
Edit : Solved, there was a trigger with a loop on the table (read
What I am looking for is a way to call a method after another

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.