0

Having some code like this one

$a = $('#a');
$b = $('#b');
$c = $('#c');

$('#a, #b, #c').keyup(function () {
    //Event handling
});

I would like to know

  1. If it is possible to use existing cached elements to handle events instead of the selector.
  2. If this is possible and proper, does it make any difference?
1
  • 1
    Sure, $a.add($b).add($c).keyup( ... Commented Jun 27, 2014 at 20:12

1 Answer 1

1

Of course, using cached elements is better for performance. If you want to bind a function on multiple cached elements, you can use .add() :

$a.add($b).add($c).keyup(function(){});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.