When you click on the button with the remove class, you need to get the id of the form in which this button is located. Here is the code with two forms (Two identical forms with different IDs (generated using PHP)):

"Two identical forms with different IDs (generated using PHP)

And I have the following script

$(".remove").on("click", function(){ alert ($(this).parent().parent().attr("id")); });

  • I am sorry, the picture with the code was not added - Sergey
  • Yes, it is in $(document).ready(function(){ ... }); - Sergey
  • Describe the current behavior. Options: the alert not shown, the alert is shown with the wrong text, the browser is closed, the computer is turned off. - Igor
  • Did not show alert - Sergey
  • Everything worked, there was a minor code error) Thank you) - Sergey

1 answer 1

What happens in your code? It corresponds to the DOM structure shown. The script inside $(document).ready(function(){ ... }); ?

https://api.jquery.com/closest/

 alert($(this).closest("form").attr("id")); 
  • one
    I started to collect the solution, and when I returned to the page, it was already there. Almost the same, but in dynamics: codepen.io/shugich/pen/LymRLW - dmitryshishkin
  • Thanks, your script has helped, it seems somewhere an error is inside the code. I will look for. On the changed script works for me (Added several forms with different id) - Sergey