Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace an anchor with its innerHTML
    text
    copied!<p>I want to replace a link with its innerHTML, how is it done?</p> <p>Example:</p> <pre><code>Bla bla bla &lt;a href="#nogo"&gt;No link here&lt;/a&gt; bla bla bla </code></pre> <p>has to become</p> <pre><code>Bla bla bla No link here bla bla bla </code></pre> <p>Tried to replace the node with its innerHTML but I can't get the text in the node itself..</p> <p>I guess I have to work with regular expressions but I can't figure out how.</p> <p>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.</p> <p>I am using prototype js as well.</p> <p>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:</p> <pre><code>&lt;td id="text"&gt;This is some text &lt;a href="/link/Go_%28To%29" title="Go (to)"&gt;goto&lt;/a&gt;. Some more text.&lt;/td&gt; </code></pre> <p>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..</p> <p>However when I alert</p> <pre><code>$('text').childElements()[0] </code></pre> <p>The actual <strong>href</strong> get's alerted! (localhost//link/Go_%28To%29)</p> <p>$('text'.childElements()[0].up() gets me to the actual td parent element.</p> <p>So I am using</p> <pre><code>if($('text').childElements()[0]) </code></pre> <p>To check wether the text contains a link.</p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload