One element, multiple events

In jQuery you can easily do it like this:

$("#foo").focus(function () {
    // Do this.
}).blur(function () {
    // Do that.

Can we do something similar in JavaScript so we don’t have to repeat #foo in two separate functions?

Yes, if the function is designed that way.

For example:

function Helper() {
    var helper = this;
    return function (selector) {
        return helper;
var helper = new Helper();

Helper.prototype.blur = function () {
    return this;
Helper.prototype.focus = function () {
    return this;


Thanks for the sample code, but it seems that using two separate functions for #foo is easier than a helper.