That's because those are not the same strings:
var background = jQuery(".sl-slide:visible .bg-img").css("background-image"))
If you do that, background
will have the value of url("http://pacificolife.com/wp-content/uploads/2016/08/bw1-1.jpg")
No matter if on your css file, you write:
.sl-slide:visible .bg-img {
/* with '' */
background-image: url("http://pacificolife.com/wp-content/uploads/2016/08/bw1-1.jpg");
/* without '' */
background-image: url(http://pacificolife.com/wp-content/uploads/2016/08/bw1-1.jpg);
}
The output will always be the same.
Solutions:
- Do the comparsion with the exact same string.
- Remove the URL(). Based on this answer:
Code:
var bg = jQuery(".sl-slide:visible .bg-img").css("background-image"));
var url = bg.replace(/(?:^url\(["']?|["']?\)$)/g, "");
console.log(url === 'http://pacificolife.com/wp-content/uploads/2016/08/bw1-1.jpg');
// true
Check this fiddle