I am using this code to get the background image of a div
.
var bgImage = $('#content').css('backgroundImage');
This is returning url%28http://example.com/images/layout/content-trans.png%29
I know you can do element.height()
to get an element's height without px
appended (parseInt()
also works), so I was wondering if there was a similiar method for jQuery to get the actual background image minus the url()
meta data.
I suppose I could use a regular expression, something like /url\((.*)\)/
, but I'd rather know first if there is an built-in way.
url() is part of the value of background-image, so I guess you need to use regex replace.
var bgImage = $('#content').css('background-image').replace(/^url|[\(\)]/g, '');
Ref: http://groups.google.com/group/jquery-en/browse_thread/thread/d866997cb206b35f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With