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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:29:18+00:00 2026-06-14T22:29:18+00:00

I am trying to make each row in text area clickable,, the cursor can

  • 0

I am trying to make each row in text area clickable,, the cursor can be default or pointer doesn’t matter. jsfiddle

<textarea rows="10" cols="45">
hello
world
</textarea>​

I want to make an ajax call on click of text in each row. I can write all the ajax functionality, all I am trying to figure out is clicking each row in the text are.
Is it possible with text area or is there any other alternative to this.

EDIT

To be more precise, I am using <c:forEach items="${}" var=""> <c:out value="${} /></c:forEach> inside the text area. Its not exactly the text with paragraph tag. The text is dynamic based on the input selected before this page

  • 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-14T22:29:19+00:00Added an answer on June 14, 2026 at 10:29 pm

    If I understood you correctly, you want to get the text of the line you clicked on. If that is so, then the following works with your example:

    $("#mytextArea").on("mouseup", function(eventData) {
        var lineHeight = $(this).css("line-height");
        lineHeight = parseInt(lineHeight.substring(0, lineHeight.length - 2));
    
        var line = Math.floor(eventData.offsetY / lineHeight);
        alert($(this).val().split("\n")[line]);
    });
    

    DEMO – Get Text from clicked line in textarea

    The code will take the position the mouse was clicked in within the textarea offsetY and divide it by the applied line-height. Using Math.floor() it will get the line which was clicked and use it as the index element in the array when splitting the lines by "\n".

    In addition to make this work I enforced the line-height to be a set px value to allow me to calculate the line clicked.

    textarea{
        font-size: 15px;
        line-height: 15px;
    }​
    

    Edit – Scrollbars on textarea

    Assuming the textarea has a scrollbar, the scrollbar will “distort” the offsetY value and you need to add the current scroll position to it like this:

    $("#mytextArea").on("mouseup", function(eventData) {
        var scrollPosition = $(this).scrollTop()
        var lineHeight = $(this).css("line-height");
        lineHeight = parseInt(lineHeight.substring(0, lineHeight.length - 2));
    
        var line = Math.floor((eventData.offsetY + scrollPosition) / lineHeight);
        alert($(this).val().split("\n")[line]);
    });​
    

    DEMO – Get Text from clicked line in textarea with scrollbar

    I updated the CSS to a fixed height to get a scrollbar like this:

    textarea{
        font-size: 15px;
        line-height: 15px;
        height: 100px;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a notification area that will show alerts. return this.each(function() {
I'm trying to make a listview with a text and an image for each
As the title says, I'm trying to make a cell for each row a
I am trying to make a table with ten values across on each row
I'm trying to make each span rotate between a random color on 3sec intervals.
I am trying to make a long ListBox with each ListBoxItem being a tile
Im trying to make multiple quizes that will keep track of each quiz on
I'm trying to make a ListView with 2 items in each 1 list item
I am trying to make a blackjack game where before each new round, the
I'm trying to make an ajax request recursively upon each success response that is

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.