Yashika Yashika - 6 months ago 10
HTML Question

How to change the size of parent div using JavaScript

I have on div with a table inside it. The width of div is

100%
. I want to increase the size of my div as soon the table becomes grater than
400px
.

Answer

If I'm understanding correctly, my take on it is below.

You could try selecting the table, then traverse the DOM tree to select .parentElement and change the width using .style

EX:

...
var x = document.getElementById('tableID');
x.parentElement.style.width = '200%';
...
Comments