0

I have a simple html link.

<a onmouseover="myfunction(this.SOMETHING??);">The String I Want</a>

Is there any way to pass the text "The String I Want" as a variable into myfunction()? I was thinking I might be able to use the "this" keyword, so I checked here, but it didn't really address this issue.

Community
  • 1
  • 1
parap
  • 1,844
  • 5
  • 19
  • 28

1 Answers1

1

You can use this.textContentText:

<a onmouseover="myfunction(this.textContent);">The String I Want</a>

But it works in everything except IE.

innerText only works with IE:

<a onmouseover="myfunction(this.innerText);">The String I Want</a>

As suggested by others, try this:

<a onmouseover="myfunction(this.innerText || this.textContent || '');">The String I Want</a> 

This will use whichever one works, but in the event that innerText is empty and textContent is unsupported it will still pass an empty string instead of undefined.

furtive
  • 1,669
  • 2
  • 13
  • 15