Ryan Best
Ryan Best

Reputation: 13

onclick event on dynamic element not working

i am trying to attach an event listener to a static element to allow onclicks on my dynamic images to work. I cannot for the life of me seem to achieve this. I have repeatedly searched and copied the answers in other posts but to no avail.

I'm not sure what im doing wrong, whether it be a bug in my code or that im just missing something all together.

Any help would be appreciated, below is my code:

$(document).on('click','.newsfeed-bump',function(bump_hype_product){
jQuery('#product-message-confirmation-wrap').hide();
jQuery('.popup-waiting-wrap').show();
jQuery('#modal_product_message_confirmation h4.modal-title').html('');

jQuery.ajax({
    url : the_ajax_script.ajaxurl,
    type : 'post',
    data : {
        action : 'bump_hype_product',
        type : type_text,
        post_id : post_id
    },
    success : function( response ) {

        jQuery('.popup-waiting-wrap').hide();
        jQuery('#product-message-confirmation-wrap').show();
        jQuery('#product-message-confirmation-wrap').html(response);

        jQuery('#modal_product_message_confirmation').modal('show');
    }
});
                        });

Im getting "Uncaught ReferenceError: type_text is not defined"

Upvotes: 0

Views: 483

Answers (2)

Subrata Mal
Subrata Mal

Reputation: 91

Use this

$("body").delegate(".newsfeed-bump", "click", function(){
    //your code
});

or

$("body").on("click", ".newsfeed-bump" function(){
    //your code
});

Upvotes: 1

prestige Godson
prestige Godson

Reputation: 31

please try this:

$('#document').on('click','.newsfeed-bump',bump_hype_product,function(){
   // your logic
}

Upvotes: 1

Related Questions