1

My code:

var z = document.querySelectorAll("a[href='/redirect']");
for (var i = 0; i < z.length; i++) {
    z[i].addEventListener('click', function(event) {
    event.preventDefault()
    alert('OK');
    });        
}

When my script hooks into every /redirect URLs. It works but other script prevented too.

Example:

WheI I click /redirect URL

  1. Other script -> console.log(1);
  2. Other script -> console.log(2);
  3. My script -> console.log(3);

It should be:

1 2 3

But when I use the above script, it prevents all event hooked by others script and the result is:

3

Can you help my code work better?

Thank you.

Rarblack
  • 4,559
  • 4
  • 22
  • 33
Null
  • 21
  • 5
  • Try adding event listener to the parent if you can and depending upon which was clicked try to do the thing you want to do. – Rajesh Paudel Oct 11 '18 at 10:56

0 Answers0