jQuery Style How to - Set top for a div








Question

We would like to know how to set top for a div.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.11.0.js'></script>
<style type='text/css'>
#topHeadVal {<!--   ww w  .  ja v a 2s .c o m-->
  position: absolute;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $( "#topHeadVal" ).css('top','7px');
});
</script>
</head>
<body>
  <div id="topHeadVal">test</div>
</body>
</html>

The code above is rendered as follows: