1

I'm trying to write a JavaScript conditional which states, "If the #inner id's 'top' value is currently less than 500px then decrease it by 15px."

I am using jQuery and the code works fine if I remove the conditional.

But the following does not work:

if parseInt($("#inner").css("top"), 10 < 500 {
    $("#inner").css("top", parseInt($("#inner").css("top"), 10) + 15 + "px");
}

2 Answers 2

3

Syntax errors, several of them ?
Try seperating it a little so you see what's going on :

var top = parseInt( $("#inner").css("top"), 10 );

if ( top  < 500 ) {
    $("#inner").css("top", top + 15);
}
Sign up to request clarification or add additional context in comments.

1 Comment

That helped a lot. My code is a lot easier to understand now. I didn't understand that in JavaScript an if conditional needs surrounding parenthesis.
0

Error in your syntax.

var top = parseInt($("#inner").css("top"), 10);
if (top < 500) {
    $("#inner").css("top", (top + 15) + "px");
}

Would be good to read about if statetement here : W3Schools

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.