Hi,
I want to replace a link with its innerHTML, how is it done?
Example:
Bla bla bla <a href="#nogo">No link here</a> bla bla bla
has to become
Bla bla bla No link here bla bla bla
Tried to replace the node with its innerHTML but I can't get the text in the node itself..
I guess I have to work with regular expressions but I can't figure out how.
EDIT: Thank you all for the quick responses! I still can't seem to get it right. It looks like there's more going on.
I am using prototype js as well.
I got some text with could contain a link. If the text contains a link it should be replaced by it's innerHTML. It looks something like this:
<td id="text">This is some text <a href="/link/Go_%28To%29" title="Go (to)">goto</a>. Some more text.</td>
I tried using hasChildNodes() to check wether the text contained a link but it always returns yes, even when the text did not contain a link or other element. So I thought that maybe the text is considered a node too and tried childElements[1]. That returns undefined. So maybe the link is a node of the textnode then. Nothing! I am scraping this data and evalling the JSON so the weirdness may come from that. Walking the DOM in the rest of the response goes well though..
However when I alert
$('text').childElements()[0]
The actual href get's alerted! (localhost//link/Go_%28To%29)
$('text'.childElements()[0].up() gets me to the actual td parent element.
So I am using
if($('text').childElements()[0])
To check wether the text contains a link.
I guess this gets a bit off-topic but I actually can't get the a element right. Any tips? Maybe a regexp is the best option?