Yashika Yashika - 1 year ago 41
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

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


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


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