Call e.stopImmediatePropagation () from the onclick attribute

How to get event object from attribute onclick?

I tried:

<a href="something.html" onclick="function(e){e.stopImmediatePropagation();}">Click me</a>

Also, I tried this:

<a href="something.html" onclick="console.log(this);">Click me</a>

But the console just shows the item <a>.

+3
source share
1 answer

I think you would need to define the function in the tag <script/>elsewhere.

It would be so simple to use something like:

 <script type="text/javascript">
    $('#something_link').click(function(e) {
        e.stopImmediatePropagation();
    });
</script>
<a href="something.html" id="something_link">Click me</a>
+2
source

Source: https://habr.com/ru/post/1777784/


All Articles