Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  190] [ 2]  / answers: 1 / hits: 20320  / 11 Years ago, wed, march 27, 2013, 12:00:00

I have a website where user can select an item, the detail is then displayed, including the quantity. I have also included a button inside the div so that when clicked, it should decrease the quantity by 1.



        $(#btnBuy1).click(function()
{
if (!sessionStorage['quantity1'])
{
sessionStorage['quantity1']=1;

}
else
{
sessionStorage['quantity1']++;
}
$(#dropbox).html('<div id = 1><img class = thumb id = t1 src=../images/birthday_metoyou.jpg />' + teddy[1].desc + , Price £
+ teddy[1].price + , Quantity: + sessionStorage.getItem('quantity1') + <button id = 'btnRemove1'>Remove</button></div><br/>);
updateBasket();
sessionStorage[total1] = parseInt(sessionStorage.getItem('quantity1')) * teddy[1].price;
updateSubtotal();
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[1].partnum); // add the current username to the myids array
sessionStorage[ids]=JSON.stringify(myids); // convert it to a string and put into sessionStorage
}
else
{
// use cookies instead of sessionStorage
}
});

$(#btnRemove1).click(function()
{
alert(remove);
});


I put in an alert message to see if the button is working properly, but when I click the btnRemove1 button, nothing happens.


More From » jquery

 Answers
28

Since the button is dynamically added, can you try:



$(document).on('click', '#btnRemove1', function() {
{
alert(remove); //I dont know what remove was is the example, added quotes around it.
});

[#79295] Wednesday, March 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;