jquery1.7. Delegate () has been replaced by. On (), and here's an example to introduce the usage and distinction of delegate and on in jquery, and interested friends can refer to the following
In jQuery1.7. Delegate () has been replaced by. On (). For earlier versions, it still uses the most effective means of event delegation. in event bindings and delegates, Delegate () and on in general, the two methods are equivalent. . Delegate () the element specified (the child element of the selected element) adds one or more event handlers and specifies the function to run when these events occur. Code as follows://jquery 1.4.3+ $ (elements). Delegate (selector, events, data, Handler); //jquery 1.7+ $ (elements). On (events, [selector], data, handler); For example:. Delegate () code: code is as follows: $ ("table"). Delegate (" TD "," click ", Function () { alert (" Hello "); }); . On () code: code is as follows: $ (" table "). On (" click "," TD ", function () { alert (" Hi "); }); PS: The difference is seleter and events in different order delegate and on method the child elements of the selected element must be The "legal" child element. For example Copy code code as follows: $ ("table"). Delegate ("button", "click", Function () {...}); $ ("table"). On ("click", "P", function () {...}); does not work because the table child element should normally be tr,td... on (EVENTS,[SELECTOR],[DATA],FN), and the parameter [selector] is optional, A selector string is used for the descendants of the selector element of the filter's triggering event. For example: code is as follows: $ ("table"). On ("click", ". Td1", function () { Alert ("HI"); }); Filter class is TD1 the table child element and delegate selector is required.