开发者

Does changing the innerText of a DOM element result in a new layout calculation/render?

I know that certain changes to the DOM of a web-page (by JavaScript) will result in the rendering engine calculating a new layout for rendering (not sure if my terminology is correct).

I have a process that updates data fairly frequently with comet style long-polling requests. Some of these updates are fairly frequent. I know that a good general rule of thumb 开发者_C百科is to remove the target DOM element, make the necessary changes, and then put it back into the DOM (so you only get hit twice with the re-render), but I wasn't sure if you only replace the inner text of an element if you incur the same hit. In my case, I am updating the content of some table-cells, that are just text (not wrapped in spans or divs).


Any time something changes in the DOM it triggers a Repaint and Reflow. Even if you're just changing text.


yes it will be just like you want to be.

For example: you have a div with id="div" and its html setted to text of 'Lorem'

var div = document.getElementById('div');
div.innerHTML = 'Lorem Ipsum Dolor'

then you will see the div's innerHTML to be setted 'Lorem Ipsum Dolor'. this is called document reflowing.

Lorenzo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜