0

I am new to js and a bit stuck (with something that is probably very ease to fix)

I have worked out the height of a div, but I want the variable to be a negative value (so i can centre something horizontally)

Here is the wrong jquery

var modal_height = $('#modal div').outerHeight()/2;
$('#modal div').css('marginTop','-'+modal_height);

Basically as you can see im trying to make the final marginTop value a negative one (i.e. adding a minus sign before the variable)

What is the correct syntax?

1
  • 2
    you should accept @slaks's answer since you (probably) liked it Commented Apr 18, 2012 at 17:09

1 Answer 1

5

You need to use the unary minus operator: -modal_height.
This operator returns a negative number.
(If the original number is already negative, it will return a positive number instead)

Sign up to request clarification or add additional context in comments.

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.