help with javascript document object

K

kamleshbhosle

Hi

I am working on javascript wherein i am trying to highlight the
selected text by changing its background color.

What I want exactly is:
1) When a page is loaded, the user will select some text on the page by
clicking and draggin the mouse
2) I am able to extract the selected text as a string
3) I want to access the exact position of the selected text in the
document object I am using in javascript

Can you please tell me how to access the exact position of text at some
position in the HTML page using the document object, since the same
text string can appear multiple times in the HTML page.

Kamlesh
 
M

Martin Honnen

What I want exactly is:
1) When a page is loaded, the user will select some text on the page by
clicking and draggin the mouse
2) I am able to extract the selected text as a string
3) I want to access the exact position of the selected text in the
document object I am using in javascript

What kind of "position" do you have in mind? Mozilla and Opera 9 exposes
a selection object containing one (or more) W3C DOM Level 2 Range
objects where the range has a start container and start offset and end
container and end offset.

IE has its own text selection implementation with text ranges and the
possibility to store bookmarks to restore a range or selection.
 
K

kamleshbhosle

Thanks for your reply,
Actually I want to change the background color of the selected text.
so what I thought is that I will insert a HTML tag before the selected
text in the document, which the browser will reflect on the web page.
I am working on IE6.
Is there any way I can achieve this.

Kamlesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top