开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜