How To Get Background Image Url In Jquery - How To Get
How do I replace a jQuery inserted image? —
How To Get Background Image Url In Jquery - How To Get. This is required result but want to achieve the same without getting by id: For instance, if we have the following html:
How do I replace a jQuery inserted image? —
Return imageurl.replace (/ (url\ (|\)|'|)/gi, ''); In simple words, we need to create an empty div and on click event, the empty div will get the image as a background. This is all the code you need: ($element instanceof jquery)) { $element = $ ($element); You can achieve this task by using the css() method in jquery. $ (#img1).attr ('src', string.match (/.*url\ ( ['|] ( [^)]*) ['|]\)/i)); Function getbackgroundimageurl ($element) { if (! Then we can get the value of the. You can use the below code for getting the background image in jquery. // display the url to the user alert ('image.
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(')',''); Return imageurl.replace (/ (url\ (|\)|'|)/gi, ''); This is required result but want to achieve the same without getting by id: Leave a comment on cideveloper's reply. You can achieve this task by using the css() method in jquery. $ (#img1).attr ('src', string.match (/.*url\ ( ['|] ( [^)]*) ['|]\)/i)); You can use the below code for getting the background image in jquery. This is an inbuilt method in jquery to add the css property but in this case, we need to provide complete property using the url() method. // strip everything but the url itself } share. Function getbackgroundimageurl ($element) { if (!