0

How could I get the background image url of #aboutus div? I'm trying something like this

$('#aboutus').css('background')=='url(primo2.png)'

If I console log the first part of the above expression, I get

rgba(0, 0, 0, 0) url(file:///G:/u/primo2.png) repeat scroll 0% 0% / auto padding-box border-box 

And I only needed url() to compare. Thanks in advance.

Rápli András
  • 3,869
  • 1
  • 35
  • 55

1 Answers1

2

I think you are looking for this-

$(function() {
    $("div").click(function() {
        var bg = $(this).css('background-image');
        bg = bg.replace('url(','').replace(')','');
        alert(bg);
    });
});

http://jsfiddle.net/mblase75/z2jKA/2/

Actual answer: https://stackoverflow.com/a/8810040/2300749

M B Parvez
  • 808
  • 6
  • 16
  • 4
    That's it. Thank you. (It would be more ethical if you attributed the author next time: https://stackoverflow.com/questions/8809876/can-i-get-divs-background-image-url ) – Rápli András Mar 01 '14 at 17:12