I am trying to set the height of an element dynamically, so that when the document first opens, the element takes up the whole screen (adjusted for other elements on the screen - not shown in the snippet below).
I am using JQuery in my code, and the code shown below is called after the document is loaded as per the standard JQuery pattern:
$(function({
/* called here! */
});
However, I found that the results are the same - with or without JQuery, so for simplicity of the code, I have shown code that using jQuery:
<style>
#foo {
border: 1px solid red;
}
</style>
<div id="foo"></div>
<div id="foobar"></div>
<script>
const elem = document.getElementById('foo');
console.log('Element:' + elem);
console.log(`Before: ${elem.style.minHeight}`);
elem.style.minHeight = 1500;
console.log(`After: ${elem.style.minHeight}`);
</script>
How do I adjust the height of the foo
element dynamically? I used both the Height
and minHeight
attributes, and the results are the same.
In both cases, the elemnt is correctly identified, but the attribute cannot be accessed - Before and After are both empty