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

magically set or change an onClick attribute

Status
Not open for further replies.

apparition

Technical User
Aug 8, 2001
34
US
Right now, I have a script that loops through the links array and searches the href attribute of each link for a specific value. If it finds it, the href attribute for that link is changed to a javascript function call. I would much rather use the onClick event handler to call the function but I can't set it without actually typing "onClick='function call'" in the A tag. Is there a way to set it without actually typing it out?
 
In Internet Explorer, there is a property of the
Code:
event
object called
Code:
srcElement
. It is a reference to the object that the event just fired on.

How about this.

Code:
document.onclick=function() {
 if (event.srcElement.href == "doggy_style.html")
  ; // Execute code
};

What that does is this:
When the document is clicked, the script finds the element the event fired on. If it's
Code:
href
is "doggy_style.html", then execute some code. Keep in mind that this code works only in IE. I haven't found the way to get the same result in NS 6, and NS 4 simply doesn't have the support for it.
bluebrain.gif
blueuniment.gif
 
Thanks UNIMENT,
That is definately better than nothing. I can use your suggestion for IE and use my old way for all other browsers. The script already detects the browser version anyways.

Another question for ya.

Did you look that up in the jscript documentation on microsoft's site? I'm lookin for a downloadable version to use. I have the VBScript documentation but I can't remember where I found it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top