[Javascript] item.onclick = "alert('foo');";

Matt Barton javascript at mattbarton.org
Mon Nov 7 03:27:02 CST 2005


No, it won't work like that.  Try ...

	var item = document.getElementById ('foo');
	item.onclick = function () { alert ('bar'); }

Matt


Anthony Ettinger wrote:
> this doesn't seem to work:
> 
> var item = document.getElementById('foo');
> item.onclick = "alert('foo');";
> 
> http://developer.mozilla.org/en/docs/DOM:element.onclick
> 
> Anthony Ettinger
> ph: (408) 656-2473
> web: http://www.apwebdesign.com
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> --
> This email has been verified as Virus free
> Virus Protection and more available at http://www.plus.net
> 



More information about the Javascript mailing list