jquery - Convert website links dynamically to anchor tags in string using javascript -
i want add anchor tags website links in div. example bellow text in div
<div>i harsha vardhan working ssoft pvt ltd , website ssoft.com . personal website hv.com .</div>
in above text want show ssoft.com
, hv.com
in anchor tags suppose open in new tabs while clicking. text may contain number of website links.
using regex can find target link string. javascript .replace()
find every link , replace anchor tag.
$("div").html(function(i, html){ return html.replace(/(\w+\.\w+)/g, "<a href='$1' target='_blank'>$1</a>"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>i harsha vardhan working ssoft pvt ltd , website ssoft.com . personal website hv.com .</div>
Comments
Post a Comment