showing results for - "get an html img tag from a string"
Emilia
16 Oct 2017
1var div = document.createElement('div');
2div.innerHTML = post_body;
3var firstImage = div.getElementsByTagName('img')[0]
4var imgSrc = firstImage ? firstImage.src : "";
5// or, if you want the unresolved src, as it appears in the original HTML:
6var rawImgSrc = firstImage ? firstImage.getAttribute("src") : "";