-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand events tutorials to cover cases where bound elements are removed and re-added. #624
Comments
I'm not sure where this explanation would need to be. We don't have a specific section on removing/detaching elements. I don't think this is appropriate in the pages regarding events, many people will be reading those without even knowing what removing/detaching elements actually means. |
I think the above comment by @robertmaxrees could still be added as a sidenote of somekind at the end of the page that explains the events. Because it's something to be aware about. According to the documentation flow at the learning center does follow a path where you would encounter the above documentation about |
👍 Sure.
Sure. I wasn't saying it shouldn't be added somewhere, just wondering where's the best place. |
Yeah! That's what I mean. Perhaps the end of the page as a note would be a good idea. |
Originally filed in jquery/api.jquery.com#632.
There seems to be pretty regular confusion surrounding the notion that event bindings break if the element you bound to was removed from the document (via, say,
.remove()
) and then re-added (like when you create a new element with$()
).The specific issue is that people think that simply using a delegated listener is enough - e.g.:
They then later re-add
$('.someDiv')
and expect this to work because the handler is technically bound to an element that exists at the time of binding - it just happened to be removed and re-added.The
.remove()
docs helpfully explain that:This is fine, except that a lot of people aren't going to think to go to docs for
.remove()
while reading about events. This also doesn't cover cases where somebody ran something like.html('<span>no cookie for you</span>')
on a parent of the bound node, wiping it out.The text was updated successfully, but these errors were encountered: