darkling235
Programmer
I am working on a webapp which is supposed to take the string highlighted and selected by a user, and find what text node in the DOM that string is in.
So far I'm making progress. This is my code
var selObj = window.getSelection();
alert(selObj); //print out selection
//find DOM node
for(var x = 0; x < document.body.childNodes.length; x++)
{
var sel = selObj.containsNode(document.body.childNodes[x], true)
alert(sel); //print out if node contains string
//print out whole NODE
if(sel == true)
alert("TEXT " + document.body.childNodes[x].nodeValue);
}
The code gets the right selection, it claims to find the correct Node. But everytime I try to display the contents of the node (the very last part) which I really need to have access to, I get an empty string or a null. Can anyone please tell me what the problem would be? The only way I've had any luck at displaying a node is when I have torn out just about every tag or separater.
Can someone please help?
Thanks in advance
Thanks in advance
So far I'm making progress. This is my code
var selObj = window.getSelection();
alert(selObj); //print out selection
//find DOM node
for(var x = 0; x < document.body.childNodes.length; x++)
{
var sel = selObj.containsNode(document.body.childNodes[x], true)
alert(sel); //print out if node contains string
//print out whole NODE
if(sel == true)
alert("TEXT " + document.body.childNodes[x].nodeValue);
}
The code gets the right selection, it claims to find the correct Node. But everytime I try to display the contents of the node (the very last part) which I really need to have access to, I get an empty string or a null. Can anyone please tell me what the problem would be? The only way I've had any luck at displaying a node is when I have torn out just about every tag or separater.
Can someone please help?
Thanks in advance
Thanks in advance