So I am trying to get this code below to work with updating a price based on an ajax onclick:
$('#main_body li[data-pricefield="special"]').delegate('onclick','change', function(e)
{
var temp = $(this).attr("id").split('_');
var element_id = temp[1];
var pricedef = $(this).data('pricedef');
if(pricedef == null)
{
pricedef = 0;
}
$("#li_" + element_id).data("pricevalue",pricedef);
calculate_total_payment();
});
Things seem to be working ok so far – when I type in the console:
jQuery('#li_273').data('pricevalue');
I do get a value of “1.00” returned which is actually being set here on the onclick command:
'onclick' => 'jQuery(\'#li_273\').data(\'pricevalue\',\'1.00\');',
My question is what is wrong with my first block of code that is stopping this from calculating the price the right way and how do I correct it?
You are using
but
delegate‘s syntax is.delegate( selector, eventType, handler(eventObject) )and in this case you should writeThere is no
onclickevent injQueryand AFAIK anlidoesn’t have achangeevent so if you want to use multiple events then you can useAlso you can use
oninstead ofdelegate.An Example and Read more.