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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:10:46+00:00 2026-05-16T11:10:46+00:00

How to trigger a JavaScript function when someone selects a given text fragment on

  • 0

How to trigger a JavaScript function when someone selects a given text fragment on a page using mouse?
Also, is there any way to find the position of selected text on the page?

Update:
To be more clear, text fragment can be part of a sentence or a word or a phrase or whole a paragraph.

  • 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-16T11:10:47+00:00Added an answer on May 16, 2026 at 11:10 am

    Update:
    In the meantime, a "Text was selected" (DOM) event was created and is supported by all current browsers: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select_event

    Note this event only works on form elements, i.e. added to the HTMLInputElement API


    There is no "Text was selected" (DOM) event, but you can bind a mouseup event to the document.body. Within that event handler, you might just check the

    document.selection.createRange().text
    

    or

    window.getSelection()
    

    methods. There are several topics on Stackoverflow, like this one javascript to get paragraph of selected text in web page.

    I’m not sure what you mean with "finding the position", but to stay in my example world you could use the event propertys for X+Y mouse positions.

    Example: http://www.jsfiddle.net/2C6fB/1/

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

Sidebar

Related Questions

Is there a way to listen for a javascript function to exit? A trigger
How do you trigger a javascript function using actionscript in flash? The goal is
I want to trigger a javascript function (an Ajax Post save function) when someone
How can I set a delayed trigger in JavaScript to execute a function after
I have this Javascript: <script language=javascript type=text/javascript> $().ready(function() { $('#ex2').jqm({ajax: 'view.php?id=<?=$objResult[id];?>', trigger: 'a.ex2trigger'}); });
I want to trigger javascript alert using PHP. Is it possible I want to
The API documentation does not contain an obvious way to trigger a javascript event
I am trying to pass an object to a javascript function which should trigger
I'm using CKEditor for a Content Management System. When someone edits the text on
' i have a javascript function that im trying to trigger and run. here

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.