jquery-on

Should all jquery events be bound to $(document)?

给你一囗甜甜゛ 提交于 2019-11-25 22:56:23
问题 Where this is coming from When I first learned jQuery, I normally attached events like this: $(\'.my-widget a\').click(function() { $(this).toggleClass(\'active\'); }); After learning more about selector speed and event delegation, I read in several places that \"jQuery event delegation will make your code faster.\" So I started to write code like this: $(\'.my-widget\').on(\'click\',\'a\',function() { $(this).toggleClass(\'active\'); }); This was also the recommended way to replicate the

Using jQuery to test if an input has focus

与世无争的帅哥 提交于 2019-11-25 22:44:31
问题 On the front page of a site I am building, several <div> s use the CSS :hover pseudo-class to add a border when the mouse is over them. One of the <div> s contains a <form> which, using jQuery, will keep the border if an input within it has focus. This works perfectly except that IE6 does not support :hover on any elements other than <a> s. So, for this browser only we are using jQuery to mimic CSS :hover using the $(#element).hover() method. The only problem is, now that jQuery handles both