I am trying to add a click
event to an element that I appended through jQuery.
If I have the item in my HTML code the click
event works fine. I hope the code explains it better
HTML
<div id="addNew">Add new Item</div>
<div id="priceWrapper"></div>
<div class="price"></div>
JS
var data;
$('#addNew').click(function () {
$('#priceWrapper').append('<div class="item" data-js="2.5" id="Item" >(I dont work i was not here on load)I AM AN ITEM WICH COSTS 2.5€</div>');
});
$('#Item').click(function () {
data = $(this).attr("data-js");
alert(data);
});
Example in JsFiddle
Thanks for your help