Javascript – How to use jQuery variable in css?

cssjavascriptjquery

How can I use the value stored in var height, as value on for margin-top?

<script>
    $(document).ready(function(){
      var height = $(window).height() / 2;

      $("a").click(function(){

        $("#loader").css({"margin-top:", ***height});

      });

    });
</script>

Thanks in advance…

Best Answer

Like this:

<script>
    $(document).ready(function(){
      var height = $(window).height() / 2;

      $("a").click(function(){

        $("#loader").css('margin-top', height+'px');

      });

    });
</script>

Demo: http://jsfiddle.net/MtEjP/