IMO, slice
is more appropriate than substring
or replace
. Try this:
jQuery("#imageID").attr(
'src',
jQuery("#imageBlock").css('background-image').slice(4,-1)
);
Here, you’re slicing the string in between url(
and )
. See MDC on slice for a detailed description of the method.