0

I have dynamically generated links like

<a name="details" id="1" href="javascript:;">Details</a>

When one of them clicked I want to process this event with javascript code like this

$(document).ready(function () {
    var a = document.getElementsByName('details').item(0);

    a.on('click', function () {
        $.ajax({
            ///
        });
    });
});

However, even though it seems to find hyperlinks quite perfectly, on click event it doesn't enter the function.

What is wrong with the implementation?

Craig
  • 6,869
  • 3
  • 32
  • 52

1 Answers1

-1

on is a method you find on jQuery objects.

document.getElementsByName('details').item(0) returns a native DOM element.

Either use addEventListener instead of on or $("some selector") instead of getElementsByName & item.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335