Search code examples
jqueryjquery-uiresizeresizablejquery-ui-resizable

JQuery Resize div


I want to add a div on a click and automatically start the resize mouse ui functionality with the mousedown.

I can add the div easily, I have the resize functionality easy. But I can't figure out how to pass the mouse event and bind them so that the resize can start right away.

Imagine a painting like program so the div can be added and drawn by dragging the mouse...?

Thank you so much.


Solution

  • Because your divs are added to the DOM AFTER the initial event handlers are bound, .bind() won't work on the new elements. jQuery has a nifty .live() method which will do the same thing as .bind(), but to elements added to the DOM later on.

    So, you could write something roughly like this:

    $('.my_new_div').live('mousedown', my_resize_handler);

    jQuery Live

    Edit: also look at the new .delegate() method. Very similar to .live() but more efficient.