472,986 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Select DOM node(s) via text highlighting

Hello,

I am new to javascript.
I want to be able to do the following if possible:

1) Use the mouse to highlight a section of text on a page.
2) Obtain references (via javascript) to the node(s) that contain the
highlighted text.
3) Manipulate the html of these node(s).

I understand there is a method document.getSelection() that returns
the highlighted text. However, I am unable to obtain the container
node(s) of the text. I have also found the javascript Range API, but
I am unsure how I can interface the highlighted text from
document.getSelection() with the Range API.

Does anyone have any advice or suggestions on how to accomplish this?
Thanks,
Ralph

Jul 23 '05 #1
2 2161
Some additional information (sorry for leaving it out):
I want to do this in mozilla firefox 1.0 Gecko/20041001
This is for an intranet application.

Jul 23 '05 #2


ma**********@gmail.com wrote:
Some additional information (sorry for leaving it out):
I want to do this in mozilla firefox 1.0 Gecko/20041001
This is for an intranet application.


You need to use
var selection = window.getSelection();
which gives you a selection object with the properties and methods
defined here:
<http://lxr.mozilla.org/seamonkey/source/content/base/public/nsISelection.idl#54>
so basically if a selection has content then rangeCount is 1 (or
greater) and you can get at a range using
var range = selection.getRangeAt(0);
and that range implements the properties and methods documented here:
<http://lxr.mozilla.org/seamonkey/source/dom/public/idl/range/nsIDOMRange.idl#52>
following the W3C DOM Level 2 Range specification:
<http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Srinath Avadhanula | last post by:
Hello, Sorry to be bringing up what seems to be a somewhat beaten up topic... This is what I wanted to do: Create a _simple_ text editor widget which supports VI(M) style keybindings but...
2
by: Cali | last post by:
Please bear with me, I have been reading about XSL for a couple hours. I have an XML document that contains multiple <page> tags interspersed throughout the tree. <text> .... <page>1</page>...
4
by: G Uljee | last post by:
How can I find and select an specific item in an treeview control? I want to create a search feature on my treeview. Thanks in advance, Gaby
2
by: Wes | last post by:
I have a treeview that I am continually added nodes to. Each time a new node is added I would like to select that node. Is this possible? I have looked at selectedNode, but I don't know how to...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
1
by: gplott | last post by:
I have an XML document that has multiple childe nodes like the one at the end of this message What syntax would I use with selectNodes to select all viewentry nodes that have an entrydata...
5
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any...
2
by: naima.mans | last post by:
Hello, i want to select 2 following brothers nodes wich are one under another (one closed to another)... i have done one xslt file... but it's not really good.. for example: the xml file:...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.