how to passa a variable in javascript : i am tryng to pass a variable to the javascript but its not working ...

my code : 

    var namealert = key;
    
         $("#alerta").append("<div class='alert_item clearfix'><a href='#' id='delete_alert' onclick='localStorage.removeItem('" +namealert+ "'');'><img width='15px' style='margin-right:10px;opacity: 0.5;' src='img/error.png'></a><div class='date'>"+obj['0']+"</div><br><div class='title'>"+obj['1']+"</div><br><div class='msg'>"+obj['2']+"</div><br><a href='#' id='candidatar' onclick='candidatar()'><img width='100px' style='margin-right:10px;opacity: 0.8;' src='img/disponivel.png'></a></div>");

i get the dom out put :
[![enter image description here][1]][1]



  [1]: https://i.stack.imgur.com/7W2Rf.png

and i need it to be localStorage.removeItem('alerts_1481117090');

