Sometimes, we want to adjust the height of an element to the screen’s height with jQuery.
In this article, we’ll look at how to adjust the height of an element to the screen’s height with jQuery.
How to adjust the height of an element to the screen’s height with jQuery?
To adjust the height of an element to the screen’s height with jQuery, we can call the css
method.
For instance, we write:
<div style='background-color: green'>
</div>
to add a div.
Then we write:
const div = $('div');
div.css("height", `${$(window).height()}px`);
We select the div with $
.
Then we call div.css
with 'height'
and the height of window which we get with $(window).height()
.
We’ve to add the unit at the end to set the height.
Conclusion
To adjust the height of an element to the screen’s height with jQuery, we can call the css
method.