Skip to main content

Posts

Showing posts with the label Enter key press event in jquery

jQuery .click() vs .on() methods for adding a click event

The .click() events are only attach to fully loaded elements and can't use for dynamic added elements and utilize more memory and create event handler for each child. The .click () requires to event handler for all element which are attached and its produce the overhead at time of DOM manipulation. The  .on( )  events are used for both dynamic added elements and it’s consume less memory then .click () events. It allows creating the event handler which elements are added dynamically ways. The .on() will work for current and future elements and it a replacement of the bind() , live() and delegate() methods. The example as //For .click() event example: //HTML code < ul id = "click" > < li > List items < /li > < /ul > //For on() event example: //HTML code < ul id = "on" > < li > List items < /li > < /ul > //JavaScript code $ ( '#click li' ). click ( function () { $...

Enter key press event in jquery

I am going to share the code sample for  Enter key press event in jquery Table of Content  1. Code sample for HTML 2. Code sample for jQuery In the 1st step , we write HTML code for text-box where i can type text to search and apply to key-press event on search image button in jquery. HTML  < input type ="text" id ="txtSearchIcon" / >  < img src ="~/Images/icon_search.png" id ="imgSearchIcon" /> In the 2nd , write to jquery code jQuery // Enter key press to search by search icon. < script type ="text/javascript">     $( function () {         $( '#txtSearchIcon' ).on( ' keypress ' , function (event) {             if (event.keyCode == 13) {                           ...