I am trying to run a function using onClick in my icon. When i click on the icon, i get the error
Remove is not defined in index.php
I have defined the function in my code below but i can't tell why the issue is not being solved. What i am trying to achieve is,
I am passing the value element.id
to the function Remove(element.id)
so i can retrieve and alert the value passed in the function Remove. Any help please?
PS: Beginner with Jquery
$('#button').click(function() {
var item_name = $('#name').val();
var item_cost = $('#cost').val();
$.ajax({
url: '<?php echo base_url('shop/items'); ?>',
data: '&item_name=' + item_name + '&item_cost=' + cost,
type: 'POST'
}).done(function(result) {
var obj = $.parseJSON(result);
$.each(obj, function(index, element) {
$('#table').append("<tr><td>" + (index + 1) + "</td><td><i onclick='Remove(" + element.id + ");' id='icon' class=\"icon-refresh\" title=\"click here\"></i></td></tr>");
$('#icon').click(function() {
function Remove(item) {
alert(item);
}
});
});