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()
精彩评论