I've got a div that contains some content that's being added and removed dynamically, so its height is changing often. I also have a div that is absolutely positioned directly underneath with javascript, so unless I can detect when the height of the div changes, I can't reposition the div below it.
So, how can I detect when the height of that div changes? I assume there's some jQuery event I need to use, but I'm not sure which one to hook into.
You can use this, but it only supports Firefox and Chrome.
Use a resize sensor from the css-element-queries library:
https://github.com/marcj/css-element-queries
It uses a event based approach and doesn't waste your cpu time. Works in all browsers incl. IE7+.
This is how I recently handled this problem:
I know I'm a few years late to the party, just think my answer may help some people in the future, without having to download any plugins.
I wrote a plugin sometime back for attrchange listener which basically adds a listener function on attribute change. Even though I say it as a plugin, actually it is a simple function written as a jQuery plugin.. so if you want.. strip off the plugin specfic code and use the core functions.
Note: This code doesn't use polling
check out this simple demo http://jsfiddle.net/aD49d/
Plugin page: http://meetselva.github.io/attrchange/
Minified version: (1.68kb)
There is a jQuery plugin that can deal with this very well
http://www.jqui.net/jquery-projects/jquery-mutate-official/
here is a demo of it with different scenarios as to when the height change, if you resize the red bordered div.
http://www.jqui.net/demo/mutate/
Pretty basic but works: