0

I want to get the height in pixels of the background-image of this HTML element via jQuery, how?

<section class="profile-banner" style="background: url(http://www.mydomain.com/images/myimage.png) 50% 50% no-repeat;"></section>

update

I now have this, but I never see the height alert box alert('height:' + height);. Why?

    var url = $('.profile-banner').css('background-image').replace('url(', '').replace(')', '').replace("'", '').replace('"', '');
    alert(url);
    var bgImg = $('<img />');
    bgImg.hide();
    bgImg.bind('load', function()
    {
        var height = $(this).height();
        alert('height:' + height);
    });
Adam
  • 6,041
  • 36
  • 120
  • 208

1 Answers1

1

you shoud do something like this

var url = $('#myDiv').css('background-image').replace('url(', '').replace(')', '').replace("'", '').replace('"', '');
var bgImg = $('<img />');
bgImg.hide();
bgImg.bind('load', function()
{
    var height = $(this).height();
    alert(height);
});
$('#myDiv').append(bgImg);
bgImg.attr('src', url);
Anri
  • 1,706
  • 2
  • 17
  • 36