Teddy
Teddy

Reputation: 18572

calling e.stopImmediatePropagation() from onclick attribute

How do I get the event object from an onclick attribute?

I have tried:

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

Also, I have tried this:

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

But the console just shows the <a> element.

Upvotes: 4

Views: 4786

Answers (1)

Lucas Jones
Lucas Jones

Reputation: 20183

I think you'd have to define the function in a <script/> tag elsewhere.

Would it be that bad to simply 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>

Upvotes: 2

Related Questions