Saturday, 21 December 2013

Replace All src from Html string in javascript

var html = "<div>
    <img src="http://pranaysonisoft.blogspot.com/pranaysoni.jpg" />    <h1>SOME TEXT</h1>
    <img src="http://pranaysonisoft.blogspot.com/image2.jpg" />
</div>";


html.replace(/[^-]src\=["|'](.*?)['|"]/g, "SOME_URL");
then all src="..." become src="SOME_URL"

No comments:

Post a Comment