I have a situation where I need to add variables to the function on the OnClick event, which are previously displayed by the php script for each object, they are different on each of the objects: onclick="моя функция('переменная 1', 'переменная 2'); t .e. such onclick on one page can be set, and variables are rigidly inscribed in HTML and displayed by iterating over an array of objects in php. The function is the same for all objects.
Also, each of the objects is assigned the class class="note<?php echo $row->id; ?>" , Where the object's id added to the class by its number in the database in order to know which of them will continue to work in my js function.
In the js function, a change of переменной 2 occurs, переменная 1 always remains unchanged, this is the same object number (ID) that is added to the class, taken from the database, again needed to know which of the objects to work with.
Fully showing the function does not make sense, since in fact it works fine, but after completing it, I want to re-hang the onclick attribute on the object with the new value of переменной 2 , so that you can call the function again, which is the catch.
Here, immediately after the function call, I reset the event by click so that you can continue to work with the object and the event does not occur repeatedly anew, until I know how it can be done differently:
jQuery('.note' + id).attr('onclick', ''); Further, after working out the Ajax function, I try to re-hang the onclick attribute on the object with the new value of переменной 2 , but I already realized that this will not work:
jQuery('.note' + id).attr('onclick', 'noteAgent(\'' + id + '\', \'' + newnote + '\');'); // по русски: моя функция('переменная 1', 'новая переменная 2'); I wonder why adding the onclick attribute to jQuery does not work, and the way how it can be implemented “differently” can be using event delegation, but when delegating, I still have no idea how to pass these variables to an event handler, and “listen” The whole table for a click, when the object in it is relatively small, is not desirable.
