I am using ryanb’s simple_nested_form and i have the following Code
<%= f.link_to_add "Shipping Address", :shipping_addresses %>
I want this link to be executed only once and then it should hide. I believe i should use jquery or ajax but i don’t know much about ajax/jquery. Can anyone suggest how i can make this Link execute only once? Thanks in advance.
First of all download jQuery from http://www.jquery.com. Next add the JS file to your page.
The next thing should be something like this:
That’s about it. If you want to hide every anchor that is clicked replace #your_link_id with a as in $(“a”). Also, if you anchor tag has some class, you can hide it based on its class, like $(“a.myClass”).
UPDATE:
In relation to your comment, a code might look something like this:
Basically, when you click on a link a class named clickedOnce will be added. After that with you use .on() to tell this link to hide itself on second click.
Hope this helps.
EDIT: Here is the sample how this works: http://jsfiddle.net/rvQ4w/23/