how to add a form with a unique id on jquery?

How can jQuery distinguish certain elements made from a loop?

  • I have a loop create a bunch of buttons. I want to click a button and have jquery hide just that particular button. I realize I need different id's for each so I construct them in the loop with php like so: <form method = \"post\" action = \"\" onsubmit =  \" return addBeer('$userID','$id','$name', '$divID')\" >"; $divID = "addButton"; $tempID = $divID . $num; $divID = "#" . $tempID; print"<p id = \"$divID\"> <input type = \"submit\" value = \"Add Beer\" />  <span id=\"loader\"> </span>  </p> </form> "; But When I try and execute the javascript function addBeer I use this line to kill the particular button: $(divID).hide(); The hide does not work

  • Answer:

    I won't answer what you asked but you actually don't need different id's.You can just use $(this).parent().hide() and the parent "p" element gets hidden.And bind this with the click event of any button.

Sachin Goel at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.