jQuery: Can you find the selected element's opacity with jQuery?

Steckel picture Steckel · Jun 4, 2010 · Viewed 26.7k times · Source

I have a filter running on a set of list elements which fades the lesser desirable elements down to 0.25 opacity but I'd love to have their opacity return to 1 and then back down to 0.25 on hover over and out. Is this fairly simple to do?

I'm only having trouble finding a way to grab the selected element's current opacity so I can store it in a variable for use.

$('#centerPanel li').hover(function(){
        var currentOpacity = $(this).?????
        $(this).fadeTo(1,1);
    },
    function(){
        $(this).fadeTo(1,currentOpacity);
    });

Answer

Jeriko picture Jeriko · Jun 4, 2010

Try $(this).css("opacity")

source