Reputation: 494
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");
}
Upvotes: 1
Views: 1874
Reputation: 5419
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
Upvotes: 0
Reputation: 318182
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);
}
Upvotes: 3