Enayet Hussain
Enayet Hussain

Reputation: 1018

Get Default Background Colour

I am trying to fetch the colour of my Submit buttons background-colour on click using JQuery however when doing so the hover colour is stored instead of the default.

var originalCol = rgb2hex($("#submit").css('backgroundColor'));

How can I modify the above code to get me the default background colour rather than the hover colour?

Upvotes: 2

Views: 1157

Answers (1)

David Votrubec
David Votrubec

Reputation: 4156

You have to read the backgroundColor BEFORE you hover over the element. Obviously the hovered button has different backgroundColor.

The $(element).css() accesses the computed value.

So you should read the bgColor at the same time as when you attach the event listener.

Upvotes: 1

Related Questions