开发者

Extract Tags From HTML using Javascript

开发者 https://www.devze.com 2023-03-25 16:07 出处:网络
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.

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

精彩评论

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