View Full Version : find out the node/element that the cursor is in

08-21-2004, 01:32 AM
so I am using the Rich Text Editor located here:
and here

anyway, I am building 'improved' table functionality.. right now I'm stuck on how I can retreive the node the cursor is a child of.
I am able to insert a table with both IE and Mozilla and I am able to modify the attribute of a TD elment in this fashion with IE:

oRTE = frames[rte]
var selection = oRTE.document.selection;
rng = selection.createRange()

so then I am able to modify the attributes of a TD in any manner that I choose-- it'll probably end up being a layer/popup for a user to edit the 'desired' attributes.

But, I have been struggling trying to find a solution that would work with Mozilla. I wish it was as simple as 'getSelectedElement' .. and I try the getRangeAt() function with 0 as the argument and that claims to not be defined but it seems to work elsewhere in the script(it is not a typo, I'm not dyslexic and it still says it's undefined).

If I need to upload sample code for you to see what I'm doing better, let me know.

Willy Duitt
08-21-2004, 05:33 AM
Hi and Welcome to Coding Forums...

I recieved your P/M and I believe your problem is that Mozilla will consider whitespace as a textnode so if you are trying to walk up the tree one node, you may find yourself in an empty textnode...

And although I graciously accept your compliment, JKD knows more about this than I do and provided a good explanation of empty textnodes here (http://www.codingforums.com/showthread.php?t=43025)....

Also, at one time, Alex Vincent posted a Mozilla whitespace removing code and the link may be found in the above link.... If not, try searching on Alex's username in the Post A Javascript forum...