views:

95

answers:

3

In my code jQuery code (I know the if statement isn't jQuery), the css property "right" for the class "slider" does NOT equal 30, yet "container" is still fading out on mousedown.. What am I doing wrong? I want it to be: if the class of slider has a "right" css property equal to 30px, then fadeout the container.

$(document).ready(function() {
$(".slider").mousedown(function() {

 if ($('.slider')
 .css({'right':30})
 ) {
 $('.container')
 .fadeOut('slow');

 } 
});
});
+5  A: 

Maybe:

if($('.slider').css('right') == '30'){ ... }

There might be a unit, like px at the end of the value there. Not sure.

Atli
+9  A: 

$('.slider').css({'right':30}) returns an array object which evals to true always

you want if ($('.slider').css('right') == "30px") ...

Scott Evernden
Additional (because it might not be obvious to the OP): The code `$('.slider').css({'right':30})` is applying the right css property with a value of 30 which is why it returns an array and evaluates to true.
Andy E
yeah hadn't considered that further side=effect .. good catch
Scott Evernden
+3  A: 
$(document).ready(function() {
    $(".slider").mousedown(function() {
        if ($('.slider').css('right') == 30) {
      $('.container').fadeOut('slow');
        }       
    });
});
Jon Cram