开发者

jQuery Press Enter Not on Class

开发者 https://www.devze.com 2023-04-05 12:08 出处:网络
I开发者_如何学运维 was wondering how to press Enter but NOT when a particular class exists on the element being targeted ?

I开发者_如何学运维 was wondering how to press Enter but NOT when a particular class exists on the element being targeted ?

jQuery("#input").keypress(function (e) {
       if (e.keyCode == 13 && jQuery('.classTest').not(this)) {
         //any item selected with enter EXCEPT which has .classTest
       }
   });

?


P.S. use .input! ID's are for ONE element only.

WORKING DEMO

jQuery(".input").keypress(function (e) {
       if (e.keyCode == 13 && !(jQuery(this).hasClass('classTest')) ) {           
               alert('enter!');                   
       }
});

Code used:
!( $(this).hasClass('classTest') )
! = not
jQuery API .hasClass()

0

精彩评论

暂无评论...
验证码 换一张
取 消