Never come across this before, can anyone give me any directions?
I am creating a web application for creating notes, like notes on a blackboard. At the moment, the spawn button will create notes, but I want to make it so that the user can click anywhere on the canvas (board), and a new note will appear in this place.
Here is the code for this: -
$("#canvas").bind('click', function(e){ // Calculate offset for width, put box to the left top corner of the mouse click. var x = e.pageX + "px"; var y = e.pageY + "px"; $("#note").clone().insertBefore("#insertAfter").attr("id", "note" + noteID).show(); $("#note" + noteID).children(".title").text("Note " + noteID); $("#note" + noteID).css({left:x, top:y, "z-index" : zindex}); noteID++; zindex++; e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); });
The problem occurs when the user clicks on one of the notes, because the notes are cloned into the canvas every time the user clicks on the note, creating another note. I want to stop this behavior and ONLY create a note when the user clicks on an empty canvas area. I tried preventDefauly, stopPropagation and stopImmediate ... but none of them seem to have any effect.
I also tried them for other actions, such as clicking on a note, but just can't seem right in the right place? or am I going about this completely wrong?
an example here:
http://www.kryptonite-dove.com/sandbox/animate
UPDATE:
$('#canvas').on('click', '.note', function(e) { e.stopPropagation(); });
This solved the bubble problem, but now it prevents any click action on the notes class, I'm here in uncharted waters! would be grateful for any pointers on how to return the click action working on the title and text of the note :)