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
Related Q & A:
- How can I echo characters before and after a string?Best solution by stackoverflow.com
- How can I display older custom post outside the loop in Wordpress?Best solution by Quora
- How can I send an http request at a specific time?Best solution by Stack Overflow
- How can an individual get sponsorship for attending a conference?Best solution by idoinspire.com
- How can the EU trade be made more sustainable?Best solution by en.wikipedia.org
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.