I apply:
$(\".newContentLink\").click(function() {
$(\"#test\").append(\"1\");
});
On this:
Unable to replicate. I suspect that you're misrepresenting — oversimplifying, mostly — your situation. To be precise, I believe you're dynamically adding those inputs, and calling $(".newContentLink").click(...)
each time — which, naturally, keeps applying additional copies of the click handler to each .newContentLink
in the page.
So the most recent input you've created has one copy of the click handler and appends one 1
. The second most recent has two copies and appends 11
. The third has three and appends 111
, etc.
To prevent this, apply the click handler to your newly created DOM element, not $(".newContentLink")
(which always means every .newContentLink
).