This is the html:
<button id="btn1">CLICK 1</button>
<button id="btn2">CLICK 2</button>
<div id="show"></div>
This is the javascript:
product_id = new Array();
$("#btn").on('click', function () {
$("#show").append("<div><button type='button' id='btn1x' class='close pull-right' aria-hidden='true'>×</button>" + "<pre>button 1</pre></div>");
product_id.push("btn1");
alert(product_id);
});
$(document).on('click', 'button#btn1x', function () {
$(this).parent().remove();
alert(product_id);
//when I click this button, i want to remove the "btn1" that I pushed a while ago from my array
});
$("#btn2").on('click', function () {
$("#show").append("<div><button type='button' id='btn2x' class='close pull-right' aria-hidden='true'>×</button>" + "<pre>button 2</pre></div>");
product_id.push("btn2");
});
$(document).on('click', 'button#btn2x', function () {
$(this).parent().remove();
//when I click this button, i want to remove the "btn2" that I pushed a while ago from my array
});
I want to click the button and eventually a certain value will be inserted in the array that I made. But, I also created a close button and when I click it I want to remove the inserted value from the array.