Hello.
Faced with some kind of misunderstanding of how JavaScript works, the conclusion is as follows: the <A> link lacks the this context. I searched for information in a search engine, but it didn't work out.

 <SPAN onclick="alert(this);">test</SPAN><BR/> <A onclick="alert(this);">test2</A> 

It's on jsfiddle .
How can I access this links?

    3 answers 3

     <SPAN onclick="alert(this);">test</SPAN><BR/> <A onclick="alert(this.href);" href='abc'>test2</A> 

    Everything plows. And plowing well.

    UPD: apparently, a can not exist without specifying attribute. If in the specified example call alert (this), it will also give a link.

    • That's why I did not understand the source of the problem a = document.createElement ("a"); a.href = "asdaf"; alert (a); When converting to a string, the link simply becomes the address to which it leads. In my example, the empty string. - ReinRaus
    • one
      just as I understand it: a.toString = function () {return this.href; } So everything works fine - Zowie
    • 2
      > UPD: apparently, a cannot exist without a specifying attribute. ! [alt text] [1] [1]: i.imgur.com/Tq27w.jpg - Ilya Pirogov
    • one
      Ilya Pirogov, instead of this picture it was possible to post a comprehensive explanation of both the reasons for the placement of the picture and the specified "phenomenon". ;) - knes
    • one
      @knes - well, the man wanted to gossip a little: D - Zowie
     <A onclick="alert(this.innerHTML);">test2</A> 

    Works fine

      Looks like you just need to read about the toString() method. Example.

      Also for debugging instead of alert, it is better to use the console.log() method.

      • I’m used to the fact that converting DOM nodes usually takes the form I used to think that using the jsfiddle example to use the alert more clearly, rather than console.log, and this was my second mistake. - ReinRaus