Skip to content
Justice Tech School

focus and blur

Respond when an input gains or loses focus.

Example
$("#name").on("focus", function () {
  $(this).addClass("hl");
}).on("blur", function () {
  $(this).removeClass("hl");
});

Exercise

Lose focus.

.on("", fn)

Quiz Test

Which event fires on leaving a field?

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