msj121
msj121

Reputation: 2842

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.

Upvotes: 2

Views: 2484

Answers (1)

rbaker86
rbaker86

Reputation: 1822

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.

Upvotes: 3

Related Questions