1

i'm trying getting elements background colors

$(document).ready(function(){ $.each('.log-widget',function(){ console.log($(this).css('backgroundColor')); //$(this).css({'box-shadow':'1px 1px 20px'+}); }); }); 

it doesn't works it send me back :TypeError: invalid 'in' operand a

i would like to grab background-color of each element and return that into hex color.

2 Answers 2

3

You're iterating a string which is not what you're after. You want .each:

$(".log-widget").each(function() { ... }); 

Alternatively, you can use $.each, but with a jQuery set:

$.each($(".log-widget"), function() { ... }); 

In any case, you will have to create a set from the selector string.

Sign up to request clarification or add additional context in comments.

Comments

2

As @pimvdb pointed out, your .each syntax was wrong. To return hexadecimal colors, though, there isn't a native way. You'll have to do the conversion yourself. Take a look at this answer to a similar question: little link.

1 Comment

+1, good point. I noticed that on Chrome, the solution you linked to only accounts for elements in the DOM. Disconnected elements don't seem to have a color like red converted to hex/rgb.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.