InnerHTML manipulation in JavaScript?

The easiest solution I have found would be to place an anchor tag at the top of the div you are editing.

The easiest solution I have found would be to place an anchor tag at the top of the div you are editing: Then when you change the content of the div, you can do this to have the browser jump to your anchor tag: location. Hash = 'ajax-div'; Use this to make sure the user isnt scrolled down too far when you update the content and you shouldn't get the issue in the first place. (tested in the latest FF beta and latest safari).

It sounds like the webkit rendering engine of Safari is not at first recognizing the content change, at least not fully enough to remove the previous html content. Minimizing and then restoring the windows initiates a redraw event in the browser's rendering engine. I think I would explore 2 avenues: first could I use an iframe instead of the current 'content' node?

Browsers expect IFrames to change, however as you're seeing they're not always so good at changing content of DIV or other elements. Secondly, perhaps by modifying the scroll position as suggested earlier. You could simply move the scroll back to 0 as suggested or if that is to obtrusive you could try to restore the scroll after the content change.

Subtract the height of the old content node from the current scroll position (reseting the browser's scroll to the content node's 0), change the node content, then add the new node's height to the scroll position. Palehorse is right though (I can't vote his answer up at the moment - no points) an abstraction library like jQuery, Dojo, or even Prototype can often help with these matters. Especially if you see your page / site moving beyond simple DOM manipulation you'll find the tools and enhancements provided by libraries to be a huge help.

It sounds like you are having a problem with the browser itself. Does this problem only occur in one browser? One thing you might try is using a lightweight library like jQuery.It handles browser differences fairly nicely.

To set the inner HTML for a div with the ID of container you would simply write this: $('#container'). Html( content ); That will work in most browsers. I do not know if it will fix your problem specifically or not but it may be worth a try.

Would it work to set the scroll position back to the top (element. ScrollTop = 0; element. ScrollLeft = 0; by heart) before replacing the content?

Set the element's CSS height to 'auto' every time you update innerHTML.

I would try doing container. InnerHTML = ''; container. InnerHTML = content.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions