JQuery $(this) with class name

Hi all

I have a jsfiddle here: http://jsfiddle.net/ecWT5/

It’s 3 different colored blocks.

I want to show the color of the block on the block.

The blocks all have a class name.

So If I get the color using the class name it shows the same color on all blocks

Is it possible to use something like $(this) block with a class name to get the color of this block.

Don’t know exactly what you’re look for, but maybe something like this? http://jsfiddle.net/Strider64/4zQQu/

The way I read the post @Strider64; is he wants the colour in text on the block.

It looks like your code opens a window with the colour code when clicked - the op wants the colour code written on the block without having to click anything?

Yes I want to display the colour of the block in rgb or hex.

But thats not really the question here.

Each block has the same class name.

If I use the class name in jQuery it gives me the same colour for each block

    var color = $('.my_Box').css('backgroundColor');
    $('.my_Box span').html(color);

Is there a way in jQuery to get the different colour in each block using a class name.

Something like this? http://jsfiddle.net/Strider64/TZ9AL/1/

Yes there is, by using each (basically a loop statement) on the class and grabbing the css background-color for each class that is name my_Box.

Perfect, Thank You

A simpler version if you’re not looking for RGB to Hex conversion: http://jsfiddle.net/ecWT5/4/