Hi Jake,

I know you said to cancel your post (it had already been posted), so
you're not expecting an answer, but:

>  element = Element('div')  // Doesn't work when created this way.

It's "new Element(...)", not "Element(...)".  (See [1], scroll down to
"Element as a constructor").

>  element.attachEvent('onclick', function(evt) {alert('hello')} ); //

If you're using Prototype, why not use Prototype?[2]

[1] http://prototypejs.org/api/element
[2] http://prototypejs.org/api/element/observe

FWIW,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 31, 7:56 pm, Jake <[email protected]> wrote:
> I am using prototype 1.6.0.3 and IE8.  Although I think the same
> problem occurred in IE7. Why do the following lines of code give
> errors?
>
> <script type='text/javascript'>
>  element = Element('div')  // Doesn't work when created this way.
>  element.attachEvent('onclick', function(evt) {alert('hello')} ); //
> can't attach event.
> </script>
>
> This doesn't work either:
>
> <script type='text/javascript'>
>   element = Element('div')
>   Event.observe(element, 'click', function(evt) {alert('hello')});
> </script>
>
> However, when I do not use prototype to create the div element, both
> of these do not generate errors:
>
> <script type='text/javascript'>
>  element = document.createElement('div');
>  element.attachEvent('onclick', function(evt) {alert('hello')} );
> </script>
>
> <script type='text/javascript'>
>  element = document.createElement('div');
>  Event.observe(element, 'click', function(evt) {alert('hello')});
> </script>
>
> I was thinking that a div created with
>   element = Element('div')
> can do everything that a div created with
>  element = document.createElement('div');
> can do, but it will not allow me to attach an event for some reason.
>
> Any ideas as far as why the first two don't work?
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to