Reputation: 255
I am trying to create a basic "to-do" list in jQuery. I've gotten most of the program to work.
However, I am having trouble with my apostrophes and quotes.
I want to add some hyper-text which will exist to the right of the "to-do" item.
e.g I'M A TO DO ITEM [edit text link that will allow one to edit TO DO][remove text]
So, this hyper-text text will either allow the user to "edit" or "remove" the "to-do" item. If I use the code below, the "removeItem" appears outside of the <li>
. I am getting quite frustrated and am hoping for some assistance.
$("#addButton").on('click',function(e){
e.preventDefault();
var toDoItem= $(".tempText").val();
$("#todoList").append('<li>'+toDoItem+'<a href="#" class="edit">'+ editItem +'</a>','<a href="#" class="remove">'+removeItem+'</a>','</li>');
itemCount=itemCount+1;
$("#count").text(itemCount);
return(false);
});
Upvotes: 1
Views: 41
Reputation: 20260
Pass a single string to append()
, rather than a comma separated list of strings (so they aren't treated as individual elements, and won't be appended one after another):
'<li>' + toDoItem + '<a href="#" class="edit">' + editItem + '</a><a href="#" class="remove">' + removeItem + '</a></li>'
Upvotes: 1