I want to replace specific words (laptop, asus, acer) with links (test.com/l12, test.com/13, test.com/14) using jQuery. I found this function
<script type="text/javascript">
(function($) {
var thePage = $("body");
thePage.text(thePage.html().replace(/laptop/ig, '<a href="http://test.com/laptop">laptop</a>'));
})(jQuery)
</script>
but the problem is that it replaces laptop word in existing urls (creating urls like test.com/test.com/laptop-review if the url was test.com/laptop-review) and all the laptop html (html ids, classes, urls etc) on the page is destroyed.
Thank you