Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] To DOM or not -- calendar popup


  • From: moseley at hank.org (Bill Moseley)
  • Subject: [Javascript] To DOM or not -- calendar popup
  • Date: Wed Mar 29 23:25:59 2006

On Wed, Mar 29, 2006 at 02:43:26PM -0500, Matt Warden wrote:
> It's not that bad. Something like:
> 
> if (document.getElementById && document.createElement) {
> 	var field = document.getElementById('whatever');
> 	if (field) {
> 		var img = document.createElement('img');
> 		img.src = 'whatever.foo';
> 		img.onclick = calPopupFunction;
> 		field.parentNode.appendChild(img);
> 	}
> }

Thanks.  Yes, not bad at all.

Another thing that has been burning a hole in my to-ask file is what's
the difference between using img.onclick above vs. using
addEventListner/attachEvent -- besides being able to attach more than
one event.  Are there times when one is more appropriate?  Or are they
basically the same thing?

Prototype has Event.observe which uses those methods to attach
events, and also tracks the event for unloading -- IIRC one (the?)
reason that's done is to prevent memory leaks in IE.

-- 
Bill Moseley
moseley@xxxxxxxx