The Bumpaster The Bumpaster - 2 months ago 5x
Javascript Question

Javascript creating variable with html code with a new date variable

I do not understand what is wrong here:

var $newbox = $('<div class="ui-widget-content" id="newbox-'**+noteId**'" style="top:' + e.pageY + 'px; left: ' + e.pageX + 'px;"><span id="close">Delete comment</span><p>Your comment:</p><textarea></textarea></div>');

without this +noteId works just fine, with it firebug gives an error of missing ')'... btw thesse **** have been added so you can spot the error easier :)

here is the working code:

function makeNote(e) {
var noteDate = new date();
var noteId = noteDate.getTime();
// Check the event object if the .click is on the content
// or a created note
if (e.eventPhase === 2) {

// Create the new comment at the corsor postition
var $newbox = $('<div class="ui-widget-content" id="newbox" style="top:' + e.pageY + 'px; left: ' + e.pageX + 'px;"><button id="close" class="m-btn red"><i class="icon-trash"></i> Delete</button><button id="save" class="m-btn blue"><i class="icon-plus"></i> Save</button><textarea></textarea></div>');



function deleteNote() {

// wait until the dom document is loaded
jQuery(document).ready(function() {

// listen for a .click() event on the content element
$('#content').on('click', function(e){

// Remove the note
$("button #close").on('click',function() {


Also the deleteNote function does not work, that is why I have to make an unique id for each note, taking the time from the date gives an random number output...



Here is the answer, so the function didn't worked but I figured it out:

$('button #close').on('click', function() {