Last active
December 23, 2015 01:59
-
-
Save mojaray2k/6563903 to your computer and use it in GitHub Desktop.
Grouping inserts into a single operation is faster as it causes the page to be redrawn only once. The same goes
for style properties, where it's better to assign a css class than apply multiple styles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>UseElement Grouping to Keep DOM Touches at a Minimum</title> | |
</head> | |
<body> | |
<div id="elem"></div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript" src="element-grouping.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elem = $('#elem'), | |
arr = []; | |
for (var i = 0; i < 100; i++) { | |
arr.push('<li>element ' + i + '</li>'); | |
} | |
elem.append(arr.join('')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment