Updating an invisible element

Another technique is to set an element's display style to none. Thus, it will not need a repaint when its content is being changed. Here is a code example that shows how this can be done:

function myJS()
{
let container = document.getElementById("container1");

container.style.display = "none";
container.style.color = "red";
container.appendChild(moreNodes);
container.style.display = "block";
}

This is an easy and quick way to modify a node while avoiding multiple repaints or reflows.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset