I’m trying to build a sticky note with Javascript and jQuery. The problem I am having is, that the functions draggable() and deleteNote() can not be called on the newly appended elements. How can I fix this?
EDIT: The ID actually should get an added number, which I’m not sure how to implement, because I don’t know how to create a counter. E.g. newbox1
My code on jsfiddle: http://jsfiddle.net/wowpatrick/qexRS/4/
You need to attach the eventhandlers live, since there are no elements existent at the moment you initially called them.
Use jQuerys
live()(Attention:deprecated Docu) or with new jQuery-versionon()(Docu), to be able to attach the events on each newly created note.Also don’t use IDs, since this produces invalid markup because IDs always have to be unique. Use classes instead.