Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Get Elements Color?

Tags:

I have the follow HTML

<div>This is some <span>special <a href="#">text</a></span> and it's super</div> 

And CSS

span {color:#333;} a {color:#777;} a:hover {color:#AAA;} 

I am wondering what I can use to setup a function that I can extract the color of the <a> and <a>:hover elements?

Thanks

like image 729
Tom Avatar asked Jul 12 '10 06:07

Tom


People also ask

How to get color value in jQuery?

Use the . css() method on the element you want to retrieve. In your example: var theColorIs = $('a').

How to get the background color of an element in jQuery?

click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });

What is the use of CSS () method in jQuery?

jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.

How to set style property in jQuery?

The css() method in JQuery is used to change the style property of the selected element. The css() in JQuery can be used in different ways. Return value: It will return the value of the property for the selected element.


1 Answers

Use the .css() method on the element you want to retrieve.

In your example:

var theColorIs = $('a').css("color"); 

Which will return the color in RGB.

like image 72
RPM1984 Avatar answered Feb 06 '23 09:02

RPM1984