TCB13
TCB13

Reputation: 3155

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!

Upvotes: 1

Views: 704

Answers (2)

NoelHunter
NoelHunter

Reputation: 996

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

            simpleCart.init();

Upvotes: 0

Mohammed Swillam
Mohammed Swillam

Reputation: 9242

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.

Upvotes: 1

Related Questions