Hello, please tell me how to solve the problem. I have a code
<script> var item = JSON.parse('<%- JSON.stringify(items) %>'); var card_items = []; item.forEach(function(item){ console.log(item._id); $('.items').append('<a href="#" onclick=""><li>' + item.title + '</li></a>' + '<div id="' + item._id + '"></div>'); var inputElement = document.createElement('input'); inputElement.type = "button" inputElement.addEventListener('click', function(){ AddToCart(item._id); }); $('#'+ item._id).append(inputElement); }); function AddToCart(id){ console.log(id); } </script> `
The problem is that I can't access the div generated in this line.
$('.items').append('<a href="#" onclick=""><li>' + item.title + '</li></a>' + '<div id="' + item._id + '"></div>'); to display the buttons there, and in this line displays the error:
$('#'+ item._id).append(inputElement); of the form: "Uncaught SyntaxError: Invalid or unexpected token"