Reputation: 4873
I am trying to set the css background property of an element to a variable.
But when I log my var. to the console, it is an empty string.
Can anyone see what I am doing wrong here?
Fiddle: http://jsfiddle.net/5de0e69d/
JS:
$(function () {
var a1 = $("#adjust1");
var a2 = $("#adjust2");
var a3 = $("#adjust3");
var a4 = $("#adjust4");
var a5 = $("#adjust5");
var b = $("#gradient");
var c = $(b).css("background");
var count = 0;
$('.click').click(function (e) {
e.preventDefault();
var id = $(this).attr("id");
console.log(id);
count += 1;
var rotate = count * 36;
switch (id) {
case "adjust1":
console.log(c);
break;
case "adjust2":
console.log(c);
break;
case "adjust3":
console.log(c);
break;
case "adjust4":
console.log(c);
break;
case "adjust5":
console.log(c);
break;
}
});
});
Upvotes: 0
Views: 81
Reputation: 646
background
is a shorthand property. From http://api.jquery.com/css/:
Retrieval of shorthand CSS properties (e.g., margin, background, border), although functional with some browsers, is not guaranteed.
You may need to check background-color
, background-image
, etc.
Upvotes: 2