I am trying to select a certain value from a multi-element background-image property such as
background-image: url(a.jpg), url(b.jpg), url(c.jpg)
with a single jQuery expression.
The current solution is to replace the complete property with element.css(‘background-image’).
My intent is to enable the user to cycle through a group of background-images for the second url(), while the other background-images stay intact. Is there an easier way than replacing the complete line? I’m not very confident with regexp-replacement, any kind of help would be greatly appreciated.
No there isn’t. Even with multiple background images you still only have one attribute background-image. You need to sort out the string value yourself and hand it back. Something like the following will do the trick.
jsFiddle
This code is not meant to be optimized, but readable. The example pics are silly, they are just whatever browser windows I had open.
.data().