Home  >  Article  >  Web Front-end  >  Can multiple elements in jquery be bound to an event?

Can multiple elements in jquery be bound to an event?

WBOY
WBOYOriginal
2022-03-18 14:45:212139browse

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".

Can multiple elements in jquery be bound to an event?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

Can multiple elements in jquery be bound to an event?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn