简体   繁体   中英

jQuery, .html, add a div element

I'm trying to add a div with some details of a discount coupon so the user can confirm it before I add it to the shopping cart.

The code to the button etc... is this, and it works if I place on the website:

<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>

Then, I tried to dynamically add the code (when a php post confirms that the coupon code is OK) using jQuery, but by some strange reason it doesn't work.

I managed to write this:

$('div.cupao_confirm').html('<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>');

Without jQuery the code add the "0.00€" product to the shopping cart, so I can later send the equivalent money back to the buyer. With jQuery when I click on the link nothing happens at all. So it's not a jQuery related problem... I might be doing the .html() wrong... :( help!

Thanks!

try to use the append() method :

$('div.cupao_confirm').append("<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>");

Give it a try and let me know if it worked, Thanks.

I think maybe you need to re-initialize simple cart ager changing the shell contents. Try:

            simpleCart.init();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM