How To Get Background Image Url In Jquery - How To Get
jquery Assign background image url to a div within a template
How To Get Background Image Url In Jquery - How To Get. // get background image using css property bg = bg.replace('url(','').replace(')',''); You can use the below code for getting the background image in jquery.
jquery Assign background image url to a div within a template
You can use the below code for getting the background image in jquery. For instance, if we have the following html: This is all the code you need: You can achieve this task by using the css() method in jquery. Then we can get the value of the. In simple words, we need to create an empty div and on click event, the empty div will get the image as a background. // strip everything but the url itself } share. $ (#img1).attr ('src', string.match (/.*url\ ( ['|] ( [^)]*) ['|]\)/i)); Leave a comment on cideveloper's reply. ($element instanceof jquery)) { $element = $ ($element);
Function getbackgroundimageurl ($element) { if (! Function getbackgroundimageurl ($element) { if (! Return imageurl.replace (/ (url\ (|\)|'|)/gi, ''); ($element instanceof jquery)) { $element = $ ($element); $ (#img1).attr ('src', string.match (/.*url\ ( ['|] ( [^)]*) ['|]\)/i)); This is all the code you need: And here's a demonstration (using the same regex, but different code to better illustrate the process): // get background image using css property bg = bg.replace('url(','').replace(')',''); // display the url to the user alert ('image. // strip everything but the url itself } share. This is required result but want to achieve the same without getting by id: