Clyde Clyde - 1 year ago 88
Javascript Question

Get size of resizable div

I have this resizable div using jQueryUI. I need to get it's size every time it is resized. My code is below:

$(".resizeable_div").on("resize", function(event, ui) {
var h = $("#h").height();
var w = $("#w").width();

The code above only gets the initial size of the div. Every time I resize the div the height and width doesn't change. Any help would be much appreciated.

Answer Source

The resize event is only raised by the window. You need to hook to the stop event in the resizeable plugin, and use the ui helper to get the size. Try this:

    stop: function(event, ui) {
        var w = ui.size.width;
        var h = ui.size.height;

        // do stuff...