I came across a strange issue with jQuery. It seems that when jQuery is used to add multiple css properties with the same name (for cross browser compatibility), each "duplicate" property, is being overwritten and only the last occurrence is being used.
Example, in pure css, I have this:
div.ellipse {
background-image: radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800);
background-image: -o-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800);
background-image: -ms-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800);
background-image: -moz-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800);
background-image: -webkit-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800);
}
Fiddle: http://jsfiddle.net/Lzhcdr2f/
The background image property is used multiple times for cross browser compatibility.
Now I try to apply the above css code using jQuery like this:
$('.ellipse').css({
'background-image': 'radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)',
'background-image': '-o-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)',
'background-image': '-ms-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)',
'background-image': '-moz-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)',
'background-image': '-webkit-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'
});
Fiddle: http://jsfiddle.net/z9ygxj9j/
The above code will ONLY work in webkit browsers (chrome/safari), because the last line refers to -webkit browser, and jQuery seems to override properties with the same name and only use the last occurrence.
The only way around, seems to be this:
$('.ellipse').css({'background-image': 'radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'});
$('.ellipse').css({'background-image': '-ms-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'});
$('.ellipse').css({'background-image': '-moz-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'});
$('.ellipse').css({'background-image': '-webkit-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'});
$('.ellipse').css({'background-image': '-o-radial-gradient(center bottom, ellipse cover, #ffeda3, #ffc800)'});
Fiddle: http://jsfiddle.net/cte7ov36/
Is there no way to use the same property multiple times inside the same array?