Several buttons based on JSON have a php (information from the database in which I am using MySQL) code below I want to work with buttons, but for some reason, click handler is said only when I click on the first button in the list. Any idea why the handler does not fire for all the buttons and how can I fix it? In addition to this, Data is passing from. What is the best way to keep data in click here in Helldaler? I prefer it to not be visible in HTML if possible, but I did not know that this data for Headler Why is it convenient if I have clicked the click handler over $ at any time, then the alert is sometimes called when a button is clicked. first Next you must delegate This selector Instead of using I think if you have already set up the class for the element, then and change this piece of code to You can delegate events to The way you are binding events, they can be bound many times in the same element. Take this piece of code outside the Ajax request $ (document) .ready (function () {$ .ajax ({url: "file.php", data: "id = 1", data type: "jason", type : "Post", success: function (data) {$ .ee (data, function (index, element) {var classBtns = ""; $ each (return_error), function (i, d) { Class_button = "& lt; span class = '' 'id =' classBtn 'data-date ='" + + "'data-time ='" + element. Time + "'> press & lt; / span & Gt; "classBtns + =" & lt; p class = 'goDates'> "+ d + class_button +" ";}); $ ('div') (" Click "," $$ (this) ".data ('date'));})}}}}};
id in an HTML page < Strong> must be unique.
$ ('# classBtn') Only how many elements will be available with that ID, will get the first example.
id Get rid of
$ ("# classBtn"). ("Click", ".button" function (on "click", function () {
$ (document) {
stable ancestor instead of
document for better performance.
$ (document) .ready (function () {$ ajax ({url: "file.php", data: "id = 1", data Type: "post", success: function (data) {$ .each (data, function (index, element) {var classBtns = ""; $ .each (return_are (element.date), function (I, d) {class_button = "& lt; span class = '' button 'id =' classBtn 'data-date ='" + + D + "data-time = '" element + time + "' & gt; Press & lt; / span & gt; "classBtns + =" & lt; p class = 'goDates'> "+ d + class_button +" & lt; / p & gt; ";}); $ (' Di V ') (classBtns) attached;});}}); $ (document) .on ("click", ".button" function) {alert ("clicked" + $ (this) .data (' date '));}); });
No comments:
Post a Comment