Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11728 closed bug (fixed)

Documentation for .one (delegated events)

Reported by: NTICompass@… Owned by:
Priority: low Milestone: None
Component: event Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


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 Changed 7 years ago by dmethvin

Component: unfiledevent
Keywords: needsdocs added
Priority: undecidedlow

It's a documentation bug ... my documentation bug.

What it is trying to differentiate there is that for this case:

$(".lotsOfElements").one("click", fn);

Each of the elements with class .lotsOfElements gets its own "one" click. But for delegated events,

$("body").one("click", ".lotsOfElements", fn);

The first element clicked element with class .lotsOfElements fires the event handler and that's it. I'll clarify in the docs.

comment:2 in reply to:  1 Changed 7 years ago by NTICompass@…

Replying to dmethvin:

Yeah, I guess the docs were a bit confusing. Your explanation makes sense, thanks.

comment:3 Changed 7 years ago by dmethvin

Keywords: needsdocs removed
Resolution: fixed
Status: newclosed

Docs updated.

Note: See TracTickets for help on using tickets.