p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   How to get nodes from Selection/Range (http://p2p.wrox.com/showthread.php?t=58451)

kaps77 May 28th, 2007 06:42 AM

How to get nodes from Selection/Range
 
Hi,
Is it possible to get the nodes from the Range object?
My html consists of multiple div and span nodes, for example:
<div>start<span class="blue">text</span><span class="red">more text</span><span class="green">still more text</span>end</div
If the user selects the text between start and end and selects a class from a combo, I need to change the class of each span in the selection.
How can I get list of nodes from the Selection or Range?
Thanks,
Kapil

zaerymoghaddam June 17th, 2007 07:38 AM

Accessing list of selected nodes is not possible in this way, but I think that using 'htmlText' property of 'TextRange' object may be usefull in this situation. You can access HTML representation of selected text of document using 'document.selection.createRange().htmlText'.

This property give you a plain html code of selected portions of document. If your span elements have specific id (or specific pattern in their id), you can search this string and find what span element have been selected by user and access them by document.getElementById('span id');


All times are GMT -4. The time now is 02:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.