javascript - JS Not firing on click -


i trying load function call_ajax_add_to_quotelist via button following code:

$cartlink .= '<a class="add_to_cart button alt" href="javascript:void(0);" onclick="call_ajax_add_to_quotelist(add_to_quotelist_ajax_url,'.$product->id.');" '.$style.'>'.$label.'</a>';

the code above loading fine on view source when clicked showing dead no console error have loaded js file in function (it belongs plugin hacking wp plugin same actions of plugin)

script load:

$quotepluginjsurl = site_url().'/wp-content/plugins/dvin-wcql/js/dvin_wcql.js'; ?>         <script src="<?php echo $quotepluginjsurl; ?>"></script> <?php 

i t first check, if call_ajax_add_to_quotelist function in javascript console, , if add_to_quotelist_ajax_url correct value.

also, recommended not use onclick. recommend using jquery event binder .on().

expl.:

<?php $cartlink .= "<a class='add_to_cart button' data-id='{$product->id}'     href='javascript:;' {$style}>{$label}</a>"; // ... more products ?> 

// **one** <script> after products <script> jquery(window).on('click', '.add_to_cart.button', function() {     call_ajax_add_to_quotelist(add_to_quotelist_ajax_url, $(this).data('id'); } </script> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -