Get image from rss feed using javascript (Feed API)

3k views Asked by At
var entry = result.feed.entries[i];
var div = document.createElement("div");

somewhere in the output of

div.appendChild(document.createTextNode(entry.content));

there are several

<img src="http://ww... is there a simple way just to get image url? Maybe something with .match?

1

There are 1 answers

0
Jun Sanchez On

here's the way i did it..

var findImg = entry.content;
var img = $(findImg).find('img').eq(0).attr('src'); //i use jquery to find 1st img src

function imgFeed(){
    var defaultImg= "images/default.jpg"; 
    if(img==null){
        return defaultImg;  // if cant find any, show default image src
    }else{
        return img;
    }
}
yourElement.append('<img width="194" height="91" src="'+imgFeed()+'" alt="#" />');