Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access link

Status
Not open for further replies.

jimmyshoes

Programmer
Jun 1, 2008
132
GB
Hello

Is it possible to access a link with getElementById
I have tried the following but doesn't work

Code:
<a href="1.cfm" id="t" onclick="alert(document.getElementById('t'))">L</a>
 
You're alerting the anchor element itself, when presumably you want to get a property of it, such as the href attribute or its innerHTML?

As an aside, why would you want to use that code anyway? It's way over-complicated for the job at hand when you can use "this", e.g:

Code:
<a href="1.cfm" id="t" onclick="alert(this.href);">L</a>

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top