I'm trying to click add and the content of add will appear for the first time.
After it's added, I want to click add and it will only toggle "added", instead of adding "added" on each click
Jquery:
$(function(){
var NewContent='<div class="added">Added</div>'
$(".add").click(function(){
$("#spin").after(NewContent);
});
});
HTML:
<span class="add">add</span>
<span id="spin"></span>
Here's a Fiddle: http://jsfiddle.net/Abgec/
I tried many answers but I couldn't find the same what i looking for, but some answers helped me to achieved my goal. So i'm sharing what I done, may be it could help someone who wants to complete working code ..
*** click on "item" to toggle
still you have to clean this code, i put rough code
There may be a more elegant way, but this works.
Fiddle: http://jsfiddle.net/HVSm3/
edit: when I wrote this there were no answers I swear
All you need to do is toggle the display css property. If it is currently none, you change it to whatever display style you want. If it is currently something other than none, you change it to none.
Here is a demo: http://jsfiddle.net/7yU3n/
Docs for
.toggle()
: http://api.jquery.com/toggle/Option 1
This will work (see JS comments):
Here's a working fiddle.
Option 2
If
NewContent
does not need to be dynamic, this is a cleaner solution:HTML
JS
CSS
Here's a working fiddle.
I little different approach, replacing the click event after its first firing,
http://jsfiddle.net/Abgec/3/