E
E
Egor Mikheev2015-11-02 11:19:33
JavaScript
Egor Mikheev, 2015-11-02 11:19:33

How can you run a function when any of the listed events occur?

Hello, how can I start the launch of the function when any of the listed events occurs?

1 event:

$('.json').on('click', function () {
                        //убираем активность со всех кнопок класса и вешаем на активированную
                        $('.json').removeClass('active');
                        $(this).addClass('active'); });


2 supposedly several
$('button').on(click) ||
$('#select').on("select:close") ||
 $('.json').on('click', function () {
                        //убираем активность со всех кнопок класса и вешаем на активированную
                        $('.json').removeClass('active');
                        $(this).addClass('active'); });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Zachinalov, 2015-11-02
@SanDiesel

$('button, #select').on('click select:close', function(){})

but each of the events will be hung up on each of the elements in the selector, and this is dangerous, you need to understand what you want to get and what consequences this may have.
In this example, the click event will work for #select as well, and select:close for button as well.

I
inDeepCode, 2015-11-02
@inDeepCode

or assign each selector its own on() function (approximately as in your examples);
or write 1nu function, and pull it through onclick="" in the right tags.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question