1

I would like to be notified when a DOM element changes its dimensions. I am only targeting the latest version of Chrome. Is this possible yet?

I found:

Here's a sample of what I'd like to be able to respond to. This snippet does not print to the console, but I'd like it to since the child's width grows once the parent's width is modified.

var observer = new MutationObserver(function() {
  console.log('I fired');
});

var child = document.getElementById('child')
observer.observe(child, {
  attributes: true
});

var parent = document.getElementById('parent');
parent.style.width = '400px';
#child {
  height: 100px;
  width: 100%;
  background-color: blue;
}
#parent {
  width: 200px;
  height: 200px;
}
<div id='parent'>
  <div id='child'>
  </div>
</div>
Community
  • 1
  • 1
Sean Anderson
  • 27,963
  • 30
  • 126
  • 237

0 Answers0