Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
$(document).on("keypress", ":input:not(textarea)", function (event) {
           return event.keyCode != 13;
       });


this allowing enter key press only on textarea in my webform.

But now I want enter key activate to buttons also, so i wrote,

<pre> $(document).on("keypress", ":input:not(textarea),input:not(submit)", function (event) {
            return event.keyCode != 13;
        });


Its not woking. How to write multiple selector in the event?

What I have tried:

$(document).on("keypress", ":input:not(textarea),input:not(submit)", function (event) {
            return event.keyCode != 13;
        });
Posted
Updated 31-Dec-17 21:03pm

1 solution

You can use one single selector that excludes both the textarea and the submit button:
:input:not(textarea,:submit)
 
Share this answer
 
Comments
souvikcode 1-Jan-18 3:18am    
its working, but what if the html tag is not <input type="submit">, may be its <button type="button">. Then?
Thomas Daniels 1-Jan-18 3:26am    
Then you can just add button inside the 'not', like :input:not(textarea,button,:submit)
souvikcode 1-Jan-18 3:30am    
Thanks, its working. all tags are treated like input?
Thomas Daniels 1-Jan-18 3:30am    
The jQuery :input selector selects all input, textarea, select and button elements.
souvikcode 1-Jan-18 3:49am    
Thanks. So if any element is not under input, then how to write that in the event? Can you please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900