Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery Selector Performance
.block {
height: 50px;
background-color: black;
width: 500px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery var test</title>
<meta name="description" content="jQuery var test">
<meta name="author" content="Kevin Peters">
<link rel="stylesheet" type="text/css" href="index.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="block"></div>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous">
</script>
<!--<script src="variable.js"></script>-->
<!--<script src="reselect.js"></script>-->
</body>
</html>
$(document).ready(function() {
for (var i = 0; i < 1000000; i++) {
$('.block').css('width', getRandomInt(100, 1500) + 'px');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});
$(document).ready(function() {
var block = $('.block')
for (var i = 0; i < 1000000; i++) {
block.css('width', getRandomInt(100, 1500) + 'px');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment