On Jan 6, 2012, at 11:45 AM, Matthew Goszcz 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're probably getting something other than what you expect with the
parentNode attribute there. Prototype has a lot of dom-walking methods that get
around the problem of whitespace nodes and the like. You may *think* that the
parentNode is an element, but it's just a space.
Try this:
<ul id="thelist">
<li class="addcomment">foo</li>
<li class="addcomment">foo</li>
<li class="addcomment">foo</li>
<li class="addcomment">foo</li>
<li class="addcomment">foo</li>
</ul>
document.observe('dom:loaded', function(evt){
var list = $$('addcomment');
list.each(function(elm){
elm.observe('click', function(evt){
list.invoke('update','TEST2');
this.update('TEST');
});
});
});
And much simpler (one observer rather than a separate one on each element in
the list):
document.observe('dom:loaded', function(evt){
var list = $$('addcomment');
$('thelist').observe('click', function(evt){
list.invoke('update','TEST2');
evt.element().update('TEST');
});
});
Walter
>
> --
> 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.
>
--
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.