Home >Web Front-end >Front-end Q&A >Can multiple elements in jquery be bound to an event?
Multiple elements in jquery can be bound to an event; after binding multiple elements with one event, it will affect multiple elements at the same time. This can reduce the amount of code and does not need to bind events separately. You can use English commas To separate different elements, the syntax is "$(element object 1, element object 2,...). event".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The purpose of jQuery binding the same event to multiple elements is that when an event is triggered, it will affect multiple elements at the same time, so The amount of code can be reduced, and there is no need to bind events separately.
The following is the code for jQuery to bind the same event to multiple elements:
$('.toals,.atell,.nav').on('focus',function(){ $('.footer').css('display','none'); });
If you want to bind the same event to multiple elements, you can use commas to separate different elements. .
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of Can multiple elements in jquery be bound to an event?. For more information, please follow other related articles on the PHP Chinese website!