Hi!
I moved the code to a separate function and tried getting the element by ID 
and then using direct assignment, but it didn't rerender the picture:

config.macros.infobox.changePreview = function (textarea, imageID) {
textarea.defaultValue = textarea.value;
var value = textarea.value;
var image = document.getElementById(imageID);
image.src = value; //This doesn't refresh the image, although console.log 
correctly reports the new src
//textarea.nextSibling.firstChild.src = value; //This refreshes the image
textarea.nextSibling.firstChild.title = value;
textarea.nextSibling.firstChild.alt = value;
};

Am I missing something?

w

On Tuesday, October 28, 2014 1:44:06 AM UTC+1, Eric Shulman wrote:

> On Monday, October 27, 2014 12:33:33 PM UTC-7, whatever wrote:
>>
>> Hi!
>> I figured it out, in case anyone is interested. Instead of using 
>> setAttribute on the element, I had to use this.nextSibling.firstChild.src, 
>> because the image is the first child of the next sibling of the textarea. 
>> Same for title and alt. The setAttribute approach worked in pure HTML file 
>> though.
>>
>
> The browser's javascript engine overloads the assignment operator so that 
> *directly* setting certain attributes will have side effects.  Although 
> using setAttribute() will store the value in the element, it does not 
> trigger the side effect processing.  You can see this when setting 
> "innerHTML" on an element.  It not only sets the attribute, but it also 
> removes any previously rendered DOM 'sub-tree', and then generates an 
> entirely new DOM sub-tree based on the new attribute value.  Similarly, 
> setting the 'src' of an image element needs to use direct assignment to 
> trigger the re-rendering of the image.  Thus,
>    image_element.setAttribute('src','URL');
> will not update the image display, while
>    image_element.src='URL';
> will cause the image to change.
>
> -e
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Reply via email to