Opened 11 years ago
Closed 11 years ago
#11728 closed bug (fixed)
Documentation for .one (delegated events)
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | event | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In the docs for .one(), it says:
identical to .on() except that the handler is removed after the first time the event occurs at the delegated element, whether the selector matched anything or not
It also contains the example:
$("body").one("click", "#foo", function() { alert("This displays if #foo is the first thing clicked in the body."); });
I figured this meant, that once I clicked on the body, whether I clicked on #foo or not didn't matter, and the event would be removed. This doesn't seem to be the case, the event isn't removed until #foo is clicked on.
DEMO 1: http://jsfiddle.net/xKrPQ/
DEMO 2: http://jsfiddle.net/xKrPQ/1/
What is the correct behavior here?
Change History (3)
comment:1 follow-up: 2 Changed 11 years ago by
Component: | unfiled → event |
---|---|
Keywords: | needsdocs added |
Priority: | undecided → low |
comment:2 Changed 11 years ago by
Replying to dmethvin:
Yeah, I guess the docs were a bit confusing. Your explanation makes sense, thanks.
comment:3 Changed 11 years ago by
Keywords: | needsdocs removed |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Docs updated.
It's a documentation bug ... my documentation bug.
What it is trying to differentiate there is that for this case:
Each of the elements with class
.lotsOfElements
gets its own "one" click. But for delegated events,The first element clicked element with class
.lotsOfElements
fires the event handler and that's it. I'll clarify in the docs.