I'm having some weird behavior with appendTo()
in jQuery.
This is my JS:
$(document).ready(function() {
$("a#mydiv").click(function () {
$(this).append('<div class="well">Added div</div>' );
$(this).appendTo(div.last);
});
});
And my HTML:
<div id="last">
<center><a id="mydiv"><h3>New List</h3></a></center>
</div>
Obviously, when I click the "New List" link, I get a new <div>
added to <div id="last">
. It looks like this:
And if I keeping clicking New List
, I get more and more <div>
s. This is fine. However, when I click one of the newly-create <div>
s, it also adds one. (WHen I click the "added div" grey space). I;m going to be putting textboxes in these new <div>
s, and I don't want it adding more and more <div>
s when the user clicks to type.
What can I do to make it so new <div>
s are created only when I click the "New List" link?
Thanks!