First off, there's a problem with this line:


It will frequently fail in IE. You have to ensure that the element has
been "extended" before you can use Prototype extensions like `update`:


This isn't a problem in other browsers, just IE. Details:

Regarding the "Uncaught TypeError: Cannot call method 'update' of
null", that makes perfect sense: In this code, you ensure that all
elements with class "addcomment" have no descendant elements at all
(only a text node saying "TEST2"):


**After** which, you try to refer to the parent node of an element
that *used* to be a descendant (specifically a child) of one of those
"addcomment" elements, but which is now (as of the update above) an
orphan. You took away its parent node by clearing all of the elements
out of it. Minimal fix:

document.observe('dom:loaded', function() {
  $$('.single .addcomment .comment').each(function(element){
        element.observe('click', function(event){
            var thisAddComment = event.findElement('.addcomment');
                if (elementz !== thisAddComment) {

There we explicitly avoid clearing out the descendant elements of the
"addcomment" element that contains this "comment" element.

T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Jan 6, 4:45 pm, Matthew Goszcz <matthew.gos...@gmail.com> wrote:
> I'm a newcomer to prototype but every time I try to run the
> following...
> document.observe('dom:loaded', function() {
>   $$('.single .addcomment .comment').each(function(element){
>     element.observe('click', function(event){
>       $$('.addcomment').each(function(elementz){
>         elementz.update("TEST2");
>     });
>       element.parentNode.update("TEST");
>     });
>   });
> });
> I get an error "Uncaught TypeError: Cannot call method 'update' of
> null". Can you please help I'm trying to reset every .addcomment
> element to say TEST2 except for clicked element to say TEST, but only
> one element at the time can say TEST.

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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to