The thing is that someone who knows Prototype knows that update
changes the innerHTML of an element. If another programmer sees your
code and sees you're updating an image, he'll be a little puzzled :)

If you use image.src = path, or image.setAttribute("src", path) or
image.writeAttribute("src", path) or image.writeAttribute({ src: path
}), the intent will be much clearer. And if you want to use update
because of the chaining that Prototype allows, using
Element#writeAttribute also returns the extended element :)


On Jan 24, 2008 11:33 PM, dynamo517 <[EMAIL PROTECTED]> wrote:
> I am using prototype version 1.6.0.
> Currently when updating typical (e.g. SPAN, DIV, TD, etc.) DOM
> elements, a simple
>   $('div1').update('new text');
> would update the text of the element.  That's fine, but what about
> images?
> If I do that with an image tag, I would hope to be updating the src,
> but it currently silently does nothing.  No error; nothing.
> Temporarily, I extended all images such that when update() is called
> on them, I can pass a new src attribute and that will be set.  Here's
> what I did:
> Element.addMethods
> (
>   'IMG',
>   {
>     update: function(element, src)
>     {
>       element = $(element);
>       element.setAttribute('src', src);
>       return element;
>     }
>   }
> );
> $('img1').update('images/newImage1.gif');
> By the way, I'm aware that another workaround would be to just
> directly set the attribute of any image I want by
>   $('img1').setAttribute('src', 'images/newImage1.gif'');
> but the point is to unify elements using the update function.
> Is the original prototype update function doing it wrong for images?
> If not, maybe this could be a new feature.
> >

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at

Reply via email to