faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 26 people (65%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How do I attatch an onclick event to an image in NS4 without using a href tag, and will it still work in IE4+

Apr 30th, 2001 04:54
Colin Fraser, Mark Fritz,


The only way of stimulating a user to cause an event is to generate a 
mouse click or a keypress, or a mouse move.  You can use the body tag :
<body onClick="dothis()" onMouseMove="doThat()" 
onKeyPress="doSomething()";msDoSomethingElse() bgcolor="#ffffff">
This may prove unwieldy for what you require in relation to an image so 
try this instead :
<a href="javascript:void" onMouseOver="dothatThing()" 
onClick="dothisthing()"><img src="myimage.gif" border=0></a>
The short answer is that there are few objects you can use to generate 
an event, the <a href="..> is probably the most obvious to use.