Created
November 12, 2019 17:10
-
-
Save kheniparth/ab8b48871a4dd3c2d0bbe13610f77fea to your computer and use it in GitHub Desktop.
JavaScript - Find external link anchor tag and replace html content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var regex = /<a(.+?(?=href))href="((http|https):\/\/(?!www.techmuzz.com)[\w\.\/\-=?#]+)"(.*?)>(.*?)<\/a>/g; | |
var replaceAnchor = '<a$1href="$2"$4>$5 <img src="https://techmuzz.com/favicon.ico"></a>'; | |
var htmlElement = jQuery('.entry-content'); | |
var updatedHtml = htmlElement.html().replace(regex, replaceAnchor); | |
htmlElement.replaceWith(updatedHtml); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment