[Javascript] To DOM or not -- calendar popup
Matt Warden
mwarden at gmail.com
Thu Mar 30 01:03:29 CST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bill Moseley wrote:
> 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?
I'm not the best person to answer your question. I did a little googling
and I did find this:
"the event fired from the onevent attribute will always fire before any
events attached using attachEvent "
http://siteexperts.com/forums/viewConverse.asp?d_id=16454&Sort=0
So it does seem like they are different mechanisms, not simply different
ways of doing the same thing.
See also:
http://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html
This code might help you:
http://mwarden.f2o.org/sandbox/viewsource.php?linemode=0&f=eventlistener2.js
- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFEK4LBrI3LObhzHRMRAoSNAKDQJI4JgIOkhP1Z3PYBToQiocjqbwCfRK/M
sMp0VpEAF29OgMT/X5kZPEw=
=nAqm
-----END PGP SIGNATURE-----
More information about the Javascript
mailing list