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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:57:31+00:00 2026-05-25T21:57:31+00:00

is there a jquery selector for text that is highlighted after its dragged over

  • 0

is there a jquery selector for text that is highlighted after its dragged over by the mouse cursor? For example, I want to select text that I’ve typed into my textarea field, click a button, which puts <p> tags around the text I’ve highlighted with my mouse cursor. A non-plugin solution would be preferred, thanks.

  • 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-25T21:57:31+00:00Added an answer on May 25, 2026 at 9:57 pm

    There’s a straight up javascript solution that’s pretty nice… just use inputElement.selectionStart and inputElement.selectionEnd .

    It’s helpful to note that this is just on Dom elements, so you’ll have to take your jQuery selector for your textarea and add [0] to get the element itself, ie. $("#myTextArea")[0].selectionStart.

    From there you can do some string work and add in your <p> tags at the appropriate indexes.

    I haven’t tested this, but it should work…

    var selStart = $("#myTextArea")[0].selectionStart;
    var selEnd = $("#myTextArea")[0].selectionEnd;
    
    var originalString = $("#myTextArea").val();
    
    var segment_1 = originalString.substr(0,selStart);
    var segment_2 = originalString.substr(selStart,selEnd);
    var segment_3 = originalString.substr(selEnd,originalString.length);
    
    var finalString = segment_1 + "<p>" + segment_2 + "</p>" + segment_3;
    
    $("#myTextArea").val(finalString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a jquery plugin that when you hover over an icon etc. it
There is a bug in jQuery 1.4.2 that makes change event on select-element getting
Is there a JQuery selector to select all elements which do not have certain
Is there any way to get the text of the selector that invoked some
Is there a case insensitive version of the :contains jQuery selector or should I
what does it mean where there are two id's in the jquery selector using
Is there a way to set multiple alsoResizes in jQuery UI? $('.selector').resizable({ alsoResize: '.other'
Are there any jQuery 1.3 animation-transitions that work in both Firefox 3 and IE7?
Is there a jQuery way to perform iteration over an object's members, such as
Is there a jQuery project out there, that create on of these Password-strength-meters right

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.