简体   繁体   中英

Get background-image url value

I have 7 divs each one with a different background-image and I need to get the url of each background image passed inline in the html, can someone help me with that?

I've tried different ways but with no success :(

http://jsfiddle.net/e46bf/

use .each to cycle through all the div, to get background images.

$("div").each(
    function(index) {
        var thisUrl = $(this).css("backgroundImage");
        var content = $("p").html(); // current content
        $("p").html(content+" "+thisUrl);
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM