patrickzdb
patrickzdb

Reputation: 1073

How do I write this jQuery more efficiently?

This is a really basic example, but I'm still a beginner with jQuery and I always struggle with combining jQuery events (functions?).

$(function () {
    $(document).on('focus', 'input[type=text]', function () {
        this.select();
    });
});

I'd like to add in .on('focus', 'input[type=email]' and .on('focus', 'textarea', without creating a whole new .on function.

Upvotes: 0

Views: 45

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use multiple selector for that,

$(function () {
    $(document).on('focus click touch', 'input[type=text],input[type=email], textarea', function () {
        this.select();
    });
});

Upvotes: 1

Related Questions