Updating the DOM Faster with .innerHTML J Query

Problem
You’re creating a large block of HTML code and using $('#mydiv').html(myhtml); to insert it into the DOM. You’ve profiled the code and found that the .html() method is taking longer than expected.

Solution

for faster DOM updates—if you don’trequire any of the special processing that .html() provides.

Discussion
The .html() method uses the .innerHTMLproperty to actually insert the HTML content into the DOM, but it does quite a bit of preprocessing first. In most cases this won’t matter, but in performance - critical code you can save some time by setting the.inner HTML property directly.
It’s actually jQuery’s internal .clean() method that does this processing. If you read the source code for .clean(), you’ll see that it goes to quite a bit of work to clean up the HTML input.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics