Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

How can I get JQuery to replace the non URL parts of the string when fetching the background images url

$
0
0

I have this code which extracts the element for the background image, however it pulls in the " url'" parts of the code too. I just need the actual image address

I have tried to use the replace function but it doesn't do anything to the string when i check the output.

var jsonData =
{ "image": jQuery('#block-content').css('background-image').replace(/^url\(['"](.+)['"]\)/, '$1'),
var script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(jsonData);
jQuery("head").append(script);

The image inside the element is //imageaddress.jpg so it's extracting it as

https://example.com/recipes/url(https://example.com/sites/image.jpg?itok=jfzYQHZx)

How can i fix this so that it just gives me

https://example.com/sites/image.jpg?itok=jfzYQHZx

Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>