Suppose I have an HTML page that looks something like this:
<html><body>
00123
<input value="00123">
00456
</body></html>
And I want to use javascript / jQuery so that it looks like this:
<html><body>
<a href="#00123">00123</a>
<input value="00123">
<a href="#00456">00456</a>
</body></html>
Essentially, I want the regular expression to match the simple lines in the document with the HTML anchor tags. In this example, I want to do something like:
$('body').html($('body').html().replace(/(00\d+)/, '<a href="#$1">$1</a>'));
See jsFiddle in this example: http://jsfiddle.net/NATnr/2/
The problem with this solution is that the text inside the element is inputmatched and replaced.
Does anyone know how to only match and replace plain text in a document this way using javascript / jQuery?
source
share