79244948

Date: 2024-12-02 17:09:03
Score: 0.5
Natty:
Report link

For anyone finding this question from a search engine, if your calling element is a link, like so:

<a href="javascript:myFunction(this)">Link</a>

And if your JS looks like this:

function myFunction(caller) {
    console.log(caller);
}

Then the output will be incorrect and massive in size!

Instead use:

<a onclick="myFunction(this)">Link</a>

Then the output will be just the calling element.

See also: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-2):
Posted by: Danny Beckett