Ok, so I have a variable, a function, and an unordered list. I run this code:
var someid = '501bc5210642741838000000';
var liststring = '<li class="ui-state-default" id="'+someid+'">'+
'<button type="button" class="del" onclick="newfunction('+someid+');" >X</button>Slide</li>';
$('ul').append(liststring);
This code is repeated multiple times for different values of someid.
The function newfunction() looks like this:
var newfunction = function(someid){
$('#'+someid).remove();
//some other stuff; the above is the important bit
}
This is supposed to make it such that when the button is clicked, it passes someid to newfunction(), which has jQuery code that removes the list element containing the button from the DOM.
The bit that’s screwing it up is the fact that I’m enclosing the list element, etc. in a string to append it to the list HTML. I verified that the code works otherwise – I manually coded two list elements, and it ran perfectly. There’s probably some syntax I’m missing – what am I missing?
Try adding quotes to around your variable so it prints as a string and not a variable name.