How to get the style value using attr
This is what you are looking for(this code works):
$("#bgcolor").mouseleave(function(){
var bodyColor = $(this).attr("style");
$("body").attr("style", bodyColor);
});
But, instead of using attr
you should use css
, so the code will be:
$("#bgcolor").mouseleave(function(){
var bodyColor = $(this).css("background-color");
$("body").css("background-color", bodyColor);
});
JSFiddle
Check out the documentation for .css: http://api.jquery.com/css/
var bodyColor = $(this).css("backgroundColor");