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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick question 1

Status
Not open for further replies.

jaschulz

Programmer
May 20, 2005
89
FR
Does the function called by an onclick event know the id of the dom element that was clicked?

For instance, given:

<a href="#" id="DUMMY" onclick="myProc()">Dummy</a>

does myProc know it was called by DUMMY, and if it does, how do I refer to DUMMY within the body of myProc?

Thanks,

JAS
 
There are several ways around this. You could do a cross-browser lookup on the event data to determine the element in question, but it might be easier to pass it through:

Code:
function myProc(srcEl) {
   alert(srcEl.id);
}

...

<a href="#" id="dummy1" onclick="[!]myProc(this);[/!]">Dummy Link 1</a>

<a href="#" id="dummy2" onclick="[!]myProc(this);[/!]">Dummy Link 2</a>

<a href="#" id="dummy3" onclick="[!]myProc(this);[/!]">Dummy Link 3</a>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top