0

I have the following code in a ready function. The if works fine, but keeps top: 0 forever. The else statement works for the cholder element, but not the openercheck. Please advise.

    if($('.openercheck').prop('checked', false)){
    $('.openercheck').css('top', '0px');
  }
  else{

    $('.cholder').css('height', $('.slide'+classnumber).height()+12+'px');
    $('.openercheck').css('top', $('.cholder').height()+'px');
  }
2
  • Wild guess - try setTimeout(function(){ $('.openercheck').css('top', $('.cholder').height()+'px'); },0) and let me know if that works. Also, try putting the code in a $(window).load instead of a $(document).ready Commented Dec 9, 2013 at 17:36
  • Is this run once, on page-load, or inside of a change event-handler? Commented Dec 9, 2013 at 17:37

2 Answers 2

1

$('.openercheck').prop('checked', false)) always true, because return the jQuery Object. Try this:

if($('.openercheck').prop('checked')){
    $('.openercheck').css('top', '0px');
} else{
    $('.cholder').css('height', $('.slide'+classnumber).height()+12+'px');
    $('.openercheck').css('top', $('.cholder').height()+'px');
}
Sign up to request clarification or add additional context in comments.

Comments

0

First of all,

$('.openercheck').prop('checked', false)

is going to set your checked property to false.

If you want to do a condition, just do something like that:

if($('.openercheck').prop('checked') == 'false')

for the last line you can do: (but I'm not so sure atm, I prefer using .attr, or .prop and not directly .css

$('.openercheck').css('top', $('.cholder').css('height') +'px');

Hope this can help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.