JQuery Resize div

I want to add a div on click and automatically start resizing the mouse with the mouse.

I can add a div easily, I resize easily. But I can't figure out how to pass the mouse event and bind them to resize right away.

Imagine the same graphics program so that a div can be added and drawn by dragging the mouse ...?

Thank you very much.

+2


a source to share


1 answer


Since your divs are added to the DOM AFTER the initial event handlers are attached, .bind () will not work on new elements. JQuery has a great .live () method that will do the same as .bind (), but on elements added later in the DOM.

So, you can write something like this:

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



jQuery Live

Edit: Also have a look at the new .delegate () method. Very similar to .live (), but more efficient.

+3


a source







All Articles