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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:25:15+00:00 2026-06-03T13:25:15+00:00

I have an SVG element in which I have made a foreignObject. The foreignObject

  • 0

I have an SVG element in which I have made a foreignObject. The foreignObject contains two objects a textarea and a div. The textarea lies on top of the div and is transparent. When people type in the textarea the text is copied to the div (a WYSIWYG kind of editor). This all works fine. The problem is however: when you select text in the textarea (which is 100% transparent) you can’t see what text you have selected and so now I want to create a code which copies the selection to the text in the div.

I have the following to bits, this bits tells me what is selected in the textarea:

var start = e.target.selectionStart;
var end = e.target.selectionEnd;

(e is the event of a select eventlistener)

and the following selects the text in the div:

div = $(e.target).next('div');
div = div[0];

selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(div);
selection.addRange(range);

This works, but selects all text in the div. How do I constrain the selection to only the part selected in the textarea?

(by the way this code is for a demo-application and only needs to work in firefox)

  • 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-03T13:25:17+00:00Added an answer on June 3, 2026 at 1:25 pm

    I had a similar problem. My solution was to add two empty HTML elements (maybe <span class="sel-start"/> and <span class="sel-end"/>) to the output div while doing the conversion.

    You can use the same trick to show a text cursor in the div, so it’s easier for users to see where they are right now. Plus you can use the text cursor to scroll the div so it wastes less screen space.

    It’s simple to select those and they cut the text into segments which you can easily wrap in <span class="selected">...</span> elements to style them.

    Note that it’s not smart to use a single span because the selection might span block elements (p, div, lists, tables).

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

Sidebar

Related Questions

This is a part of my HTML I have embedded the SVG element. <div>
If I have inline SVG, including an element which has been scaled... <g transform=scale(sX,sY)>
i have an inline svg with foreignObject elements which contain xhtml fragments. however, the
I have a web document that contains a div element. That div element contains
I have an svg group which contains some elements, I want to clone the
I have a piece of JavaScript code which creates (using D3.js) an svg element
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>
I have a php script (generator.php) which generates certain HTML/XML/SVG depending on various conditions.
Can d3.js layout.force be used to (re)position non-svg elements like div's? If div's have
I have an SVG element inside HTML document that I'd like to export as

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.