Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2007, 06:42 AM
Authorized User
 
Join Date: Apr 2007
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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
 
Old June 17th, 2007, 07:38 AM
Authorized User
 
Join Date: Jun 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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');





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to value in b/n nodes Swetha XSLT 1 May 20th, 2008 12:20 PM
Navigate through nodes abelmirma XML 1 May 7th, 2005 07:32 AM
Range selection keithd Excel VBA 7 April 7th, 2005 11:29 AM
Exclude Nodes seanhaggerty XSLT 1 February 3rd, 2005 06:00 AM
Grouping Nodes shoei78 XSLT 3 May 28th, 2004 10:34 PM





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