Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get an html img tag from a string

var div = document.createElement('div');
div.innerHTML = post_body;
var firstImage = div.getElementsByTagName('img')[0]
var imgSrc = firstImage ? firstImage.src : "";
// or, if you want the unresolved src, as it appears in the original HTML:
var rawImgSrc = firstImage ? firstImage.getAttribute("src") : "";
Comment

PREVIOUS NEXT
Code Example
Javascript :: statusbar reactnati 
Javascript :: REACt helmet og tags DONT WORK 
Javascript :: angular dynamic class 
Javascript :: vue.js textbox 
Javascript :: javascript array group by 
Javascript :: reverse geocoding javascript map 
Javascript :: javascript format rupiah 
Javascript :: find element by two attributes jquery 
Javascript :: get month in two digit in javascript date 
Javascript :: jquery detect change in textarea content 
Javascript :: javascript date add days 
Javascript :: insert into specific array index 
Javascript :: For loop sum in javascript 
Javascript :: set view engine to ejs in express 
Javascript :: toggle button by javascript 
Javascript :: moment format a date into different format 
Javascript :: how to add text to h2 with jquery 
Javascript :: scroll event js 
Javascript :: update file json trong javascript 
Javascript :: nuxt router push 
Javascript :: forach loop in javascript 
Javascript :: javascript date time 
Javascript :: axios post with header 
Javascript :: js compare arrays 
Javascript :: node js cron example 
Javascript :: javascript string comma seprated price to int 
Javascript :: react history go back 
Javascript :: on focus jquery 
Javascript :: how to pass sequelize transaction to association helper method 
Javascript :: cypress ignore error 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =