开发者

Extract Tags From HTML using Javascript

I want to get the source of an image from html block and put it in a variable to send it to a rem开发者_高级运维ote function. How can i extract img tag from html text :


var myImageSrc = document.getElementById('myImageId').src;

or similar.


var imgs=document.getElementsByTagName("img");
for(var i=0;i<imgs.length;i++){
    var img=imgs[i];
    //do something with img.src
}

-- edit --

to remove images from the text do something like this (at the comment):

img[i].parentNode.removeChild(img[i])

What's left is the text (access it using img[i].parentNode.innerHTML)


var imageSource = document["yourImage"].src;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜