.bind(events ,data ,$)
Description:
Attach the jQuery chain behind to one or more events.
- events –
string
- A string containing one or more event types, such as "click" or "submit" or custom event names.
- data –
object
, optional - A map of data that will be passed to the event handler.
- $ – the
jQuery
token, optional - Use $ instead of a handler or leave it out.
Tip: Many other methods that internally call .bind()
and pass the handler function will automatically support that timing, too:
.click($)
,
.dblclick($)
,
.mousedown($)
,
.mouseup($)
,
.mousemove($)
,
.keydown($)
,
etc…
Usage pattern
Examples with timed version of .bind()
Example #4: blinking a given number of times on click
We repeat .toggleClass() for an even number of times, so the class "blink" is absent again when the repeat loop finishes.
Remark that the click handler is assigned directly in the invocation chain using .click($).
⇒That text blinks two times after clicking .