javascript - JQuery - Events binding and cached elements -


having code one

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

i know

  1. if possible use existing cached elements handle events instead of selector.
  2. if possible , proper, make difference?

of course, using cached elements better performance. if want bind function on multiple cached elements, can use .add() :

$a.add($b).add($c).keyup(function(){}); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -