Skip to content
Justice Tech School

The on() Method

on attaches one or more handlers, and off removes them. It is the preferred way to bind events. one runs a handler once.

Example
$('#btn').on('click', function () {
  console.log('hi');
});
$('#btn').off('click');
$('#btn').one('click', fn);

Exercise

Remove a handler.

$('#btn').('click')

Quiz Test

Which runs a handler only once?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.