I swear, this question is probably some where else but I can’t find it!!!
But here it goes:
http://jsfiddle.net/YUgxE/
Javascript:
var update = $("#CalcUpdate");
var content = document.getElementById("CalcContent");
update.click(function() { //update
content.innerHTML += "<div style='display: none' class='CalcOn'><input type='field' value='' class='CalcName'/>";
obj = $(".CalcOn");
obj.slideToggle(400,function() {
obj.removeClass();
});
});
HTML:
<button id="CalcUpdate">update</button>
Really behind this is two problems:
- Every time a new field is created, the previous field values are erased. (I don’t know why, it’s supposed to add new innerHTML lines, why do the previous values erase?)
- If I rapidly click update, the functions overlap and I don’t know how to make one execute before the other in this format. I’ve seen other questions but they all involve using two functions or something else which I’m not trying to do.
You’re using jquery, so put it to use! 🙂 Here’s how I updated your script:
http://jsfiddle.net/YUgxE/3/
Items of note:
$obj) instead of using innerHTML and adding the stringappend/appendToto add$objto$contentinstead of using innerHTMLslideToggle(thus, no lookup). This fixes the timing/order of operations problem you were seeing when clicking quickly.