Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery button click event not firing

seems like a simple issue but the solutions to the other problem don't seem to work from me.

Trying to trigger a AJAX request from a button click but it doesn't seem to be firing.

example HTML

<button class="remove_weight_button" id="15">x</button> 

javascript

$(".remove_weight_button").click(function(){     var button_id = $(this).attr("id");     $.ajax({         type: "POST",         url: "weight_tracker_process.php",         data: {             weight_id: button_id,             action: "remove"         },         success: function(){             getWeightData();         },         error: function(){             alert("data removal error");         }     });     return false; }); 
like image 373
GrepGrep Avatar asked Oct 08 '13 00:10

GrepGrep


People also ask

Why on click is not working jQuery?

jQuery click not working at the time page loading, jQuery Onclick Method is tried to an element or selector. As a result, the binding will fail if the element we wish to click isn't present when the page is ready.

Why button click is not working in asp net?

check the CausesValidation property of your button. set it to False if its true. Also check your asp.net page code file link is exactly same in which you have put the event. Is the button inside a template control (such as an <asp:Repeater> or <asp:GridView> )?


1 Answers

The code you have works fine in fiddle. Is your button being dynamically rendered through AJAX after the initial page load?

Use

$(document).on("click", ".remove_weight_button", function(){ 

instead of

$(".remove_weight_button").click(function(){ 
like image 132
Lloyd Banks Avatar answered Sep 28 '22 05:09

Lloyd Banks