Skip to content
Advertisement

HTML: How to make URLs inside of text clickable?

I cannot hand-code the <a> ... </a> since the input is a not known string.

I came up with this:

HTMLFormattingService:

JavaScript

HTML:

JavaScript

The replacing works, but the <a> ... </a> is NOT clickable with this method! That is because <a> not treated as a HTML element but just as text. So the users see the <a> and </a> and cannot click the link.

How can I fix this?

Advertisement

Answer

Keep it simple?

JavaScript
Advertisement