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!

using an event

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo is there a way to grab an event without having to modify the html code?

For example, in this code I use the onmouseover event but I need to modify the html by adding the "onmouseover...":
Code:
<a id="mylink" href="" onmouseover="alert('An onMouseOver event');return false">Test</a>

My question is if I can, in an external file, refer to mylink and use the onmouseover event, without having to modify the html. Somehitng like:

in my html
Code:
<a id="mylink" href="">Test</a>

in my script.js
Code:
if (mylink.onmouseover) then doThis()
else

 
Hi

In standard-compliant browsers :
Code:
window[teal].[/teal]onload[teal]=[/teal][b]function[/b][teal]()[/teal] [teal]{[/teal]
  document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'mylink'[/i][/green][teal]).[/teal][url=http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-addEventListener][COLOR=darkgoldenrod]addEventListener[/color][/url][teal]([/teal][green][i]'mouseover'[/i][/green][teal],[/teal]doThis[teal],[/teal][b]false[/b][teal])[/teal]
[teal]}[/teal]
For Explorer you will have to add [tt]attachEvent()[/tt] calls too.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top