the scenario...
getting the content of a div then putting that string in a textarea.
the problem is that there are links in the content.. which I thought I could solve by making the function recursive but it seems to not act as I had expected. IE returns exactly what I need.
Also, how would I be able to get the newline to be passed as well ?
BTW, I did try searching.. and I think my issue is probably more with the recursiveness since it seems to end after getInnerText() is called again.
Code:
var txt
function getInnerText(o)
{
children = o.childNodes
children_len= children.length
for (var i=0; i<children_len; i++) {
if (children.item(i).childNodes.length>0) {
getInnerText(children.item(i))
} else if (children.item(i).nodeType==3) {
txt += children.item(i).nodeValue
}
}
}
here is a sample div:
Code:
<div id="text_3" onClick="getInnerText(this);alert(txt)" style="cursor:pointer;cursor:hand;font-family:Times;font-size:8pt">31sadfasdf <a href="http://www.domain.com/?msg=21&link=http%3A%2F%2Fwww.test.com%2F">http://www.test.com/</a><br>adsfasdfadsf<br>asdfadsf<br>adsfadsf</div>