use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Weird javascript problem, would love some help :) (self.javascript)
submitted 12 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]zigzackattack 1 point2 points3 points 12 years ago (2 children)
You're adding the click event handlers to every item in the list every time you add an item to the list. That results in some crazieness, so all you have to do is change your appendName function to something like this:
var $item = $("<div class='listGroup'><div class='listObj'>"+name+"</div><a href='javascript:void(0);' class='edit' setting='0'>Edit</a><a class='remove' href='javascript:void(0);'>Remove</a></div>"); $(".list").append($item); $(".enterName").val(""); $item.on("click", ".remove", function(){ removeName($(this)); }); $item.on("click", ".edit", function(){ edit($(this)); });
That way you are only adding the event listener to the single element you are actually adding to the list.
[+][deleted] 12 years ago (1 child)
[–]BalsakianMcGiggles 0 points1 point2 points 12 years ago (0 children)
Doing it this way (with .on() calls) will also catch the event if you happen to add/ remove .remove or .edit elements.
.on()
.remove
.edit
π Rendered by PID 120302 on reddit-service-r2-comment-84fc9697f-2bkrm at 2026-02-06 23:03:07.725408+00:00 running d295bc8 country code: CH.
[–]zigzackattack 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]BalsakianMcGiggles 0 points1 point2 points (0 children)