Change DIV height/width with body width/height using jQuery

Hello Friends !!

SInce last few dyas, I am facing the problem that how can I change DIV height/width with body or browser height/width ? I want that DIV heoght is increase when browser heignt increase and decrease when browser height decrease.

In short I wnat my DIV size browser friendly. For this, I search many things in google and finally I found the solution by jQuery. In this post, I will give you code that how to change your DIV height/width with browser height/width veries.

First download latest jQuery file. After this make one DIV for which you want to change the height/width.

<div id=”test” style=”background-color:#000;”></div>

In above DIV, i give background color black so you can see the change. Now write below code in you head section.I am giveng you some code whcih use for this.

$(window).width(); => It returns width of the body

$(document).width(); => It returns width of the whole window

$(window).height(); => It returns height of the body

$(document).height(); => It returns height of the whole window

Now for an example you want the div height same as your body

then use below code. First make one div like

<div id=”test” style=”background-color:#000;”></div> I set blacj background color because you can see the change.

Suppose in your web page, there is one header which height is 100px and you want the above div height after header. So follow below code. Put this code in head section.

<script language=”javascript”>

$(document).ready(function(){

var height1 = $(document).height(); // height of full document

var height2 = $(“#header”).height(); // height of header

var height_diff = height1 – height2 + “px”;

document.getElementById(‘test’).style.height = height_diff; // Set the remaining height in test DIV.

});

</script>

Thats it. You can also use span tag instead of div. You can set your DIV height/width as page resize. If you have any confusion or query about this than comment on this.

Thanks You !

You can leave a response, or trackback from your own site.

View Comments to “Change DIV height/width with body width/height using jQuery”

  1. [...] Change DIV height/width w&#1110th body width/height using jQuery | php … [...]

  2. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  3. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  4. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  5. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  6. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  7. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  8. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  9. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  10. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  11. Flu shots says:

    [...] Change DIV height/width with body width/height using jQuery | php … [...]

  12. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  13. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  14. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  15. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  16. [...] Change DIV height/width with body width/height using jQuery | php genious [...]

  17. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  18. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  19. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  20. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  21. [...] Change DIV height/width with body width/height using jQuery | php genious [...]

  22. [...] Change DIV height/width with body width/height using jQuery | php genious [...]

  23. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  24. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  25. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  26. [...] Change DIV height/width with body width/height using jQuery | php … [...]

  27. [...] Change DIV height/width with body width/height using jQuery | php genious [...]

  28. [...] Change DIV height/width with body width/height using jQuery [...]

Leave a Reply

blog comments powered by Disqus
Subscribe to RSS Feed Follow me on Twitter!
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Thank you for using IGIT Tweet Share Button, a plugin by HackingEthics