D
D
DiseaseC2020-05-06 11:33:39
JavaScript
DiseaseC, 2020-05-06 11:33:39

How in a js file (and not in html) to make the function run when a link is clicked?

There are several links, and we need to run a script every time the user clicks on any of them. Is it possible to do this via addEventListener?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-05-06
@DiseaseC

link.addEventListener('click', (e) => {
   e.preventDefault();
   let bool = confirm('вы желаете перейти?');
    bool ? window.location.href = "http://www.example.ru" : alert('вы отменили переход');
});

From the phone, but everything seems to be so))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question