Q:

else statment not working is my syntax is incorrect on jquery?

Hi i am using if statement to change the opacity of a div on click event if a div is having the 0.5 opacity so it will change to 0 if its having 0 opacity so it will change to 0.5 i am using the following jquery code and it will change the opacity 0.5 to 0 but when i click again to change the opacity to 0 to 0.5 its not work. pls have a look on code
$("#one_star").click(function(){
    if($(this).css({"opacity":"0.5"}))
    {
        $(this).css({"opacity":"0"});
    }
    else if(!$(this).css({"opacity":"0.5"}))
    {
        $(this).css({"opacity":"0.5"});
    }
});

is i am using a wrong syntax?
any suggestion pls

A:

The expression $(this).css({"opacity":"0.5"}) you have in if should return boolean true or false but it does not so else is not executing.
try this,
if($(this).css("opacity") == "0.5")
 { 
        $(this).css({"opacity":"0"});
 }
 else 
 {
     $(this).css({"opacity":"0.5"});
 }

