I am very new to JavaScript and am trying to use JavaScript to determine the height of a div. The div starts in the middle of the browser window and I need it to extend to the bottom of the window. How can the window height be determined and used to accomplish this?

Thanks in advance!

Justin

Member Avatar for stbuchok

Look at using jQuery.

Thanks for the suggestion. I have looked into jQuery today and can use it to find the window and div height, but how can I account for the offset for a centered div?

Member Avatar for stbuchok

divide by 2 (half the width of the div)

div.left = (window.width / 2) - (div.width / 2)

That should center the div (you'll want this to happen on the resize event as well).

Thanks for leading me in the right direction! I got everything working correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.