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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:29+00:00 2026-05-20T18:24:29+00:00

I would like to find the second . (periods) before and after a insertion

  • 0

I would like to find the second . (periods) before and after a insertion in a div with contentEditable attribute set to TRUE.

For example, if I got that string into a div

<div contentEditable>           
  Lorem ipsum dolor. Sit amet, consectetur adipiscing elit. Duis semper nisl eget 
  neque feugiat consectetur. Vivamus sed mi quis dui sodales euismod et id erat. 
  Cras feugiat interdum ligula, vel. Fermentum orci accumsan quis. Donec ut lacus 
  ipsum, sit. Amet accumsan enim.
</div>

If someone insert something (with a right-click or with the keyboard directly), I would like to know where he insert his text, and find the second period before and after his insertion, to put a <br/> just after the two periods.

Here, if someone insert somethink like “New text” between “Vivamus” and “sed”, I would like to do that:

<div contentEditable>           
  Lorem ipsum dolor. Sit amet, consectetur adipiscing elit.<br/> Duis semper nisl eget 
  neque feugiat consectetur. Vivamus sed mi quis dui sodales euismod et id erat. 
  Cras feugiat interdum ligula, vel.<br/> Fermentum orci accumsan quis. Donec ut lacus 
  ipsum, sit. Amet accumsan enim.
</div>

I really don’t know how to locate the insertion and how to find the periods (I successed with .find(":contains('.')"), but i think there is another better solution…)

Thanks in advance for helping!

  • 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-20T18:24:30+00:00Added an answer on May 20, 2026 at 6:24 pm

    Finding the caret position is just plain annoying due to browser-differences, but there are libraries out there that do it (google “javascript caret position”).

    Once you have the caret position (e.g. 100), finding the periods around it:

    var twoForwardPos = text.indexOf('.', text.indexOf('.', caret+1) +1);
    var twoBackPos    = text.lastIndexOf('.', text.lastIndexOf('.', caret-1) -1);
    

    The .indexOf and .lastIndex of functions take a 2nd argument that is an offset. "foo".indexOf('o') == 1, whereas "foo".indexOf('o', 2) == 2

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

Sidebar

Related Questions

I would like to find the second highest variable in an array. For example
i would like to find a formula describing this series. i need to set
I would like to find a way to see what happens while my XAML
I would like to find the values of some of windows API constants, such
I would like to find a way to compile and package our iPhone application
I would like to find the files containing specific string under linux. I tried
I would like to find a way to use custom User provider within a
I would like to find some tutorial about the trading algorithms like Iceberg, Dagger,
I would like to find out if any and which database links are being
I would like to find all comment blocks(/*...*/) but the function g_regex_match_full always returns

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.