[Javascript] To DOM or not -- calendar popup

Bill Moseley moseley at hank.org
Wed Mar 29 23:25:50 CST 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 at hank.org




More information about the Javascript mailing list