How to get the style value using attr

Dilini Wasana picture Dilini Wasana · May 14, 2013 · Viewed 48.3k times · Source

My HTML CODE HERE:

 <i id="bgcolor" style="background-color: rgb(255, 146, 180)"></i>

I want to get the background-color value using jquery attr. What i tried is below:

$("#bgcolor").mouseleave(function(){
        var bodyColor = $(this).attr("style");

        $("body").css(bodyColor);
    });

But this output is:

background-color: rgb(255, 146, 180);

And now that I've added it to my css it will not work. How can I achieve this task?

enter image description here

Answer

dwaddell picture dwaddell · May 14, 2013

Check out the documentation for .css: http://api.jquery.com/css/

var bodyColor = $(this).css("backgroundColor");