开发者

getting src, width, height and alt of image (outerhtml) basically, mapping to an array

How would I get these values for example with these images and map them to an array.

<img height="307" width="256" src="http://upload.wikimedia.org/wikipedia/en/6/6a/MystCover.png" alt="MystCover.png">

<img height="135" width="220" class="thumbimage" src="http://upload.wikimedia.org/wikipedia/en/thumb/d/d0/Myst-library_and_ship.jpg/220px-Myst-library_and_ship.jpg" alt="">

I currently use this code just t开发者_StackOverflow社区o test getting the src and it works well, but I need to get something like the "outerHTML" or .

   var images = $('img:area(10000)').map(function(){
    return $(this).attr('src');
}).get();


You could do this to get all those attributes:

var imageArray = $('img:area(10000)').map(function(){
    return {
        src: $(this).attr('src'),
        width: $(this).attr('width'),
        height: $(this).attr('height'),
        alt: $(this).attr('alt'),
        html: $(this).html()
    };
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜