Editing my vs jQuery This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> var my = { each : function(itemArray, itemCallback) { for (var i = 0; i < itemArray.length; i++) { itemCallback(itemArray[i], i); } }, addClass : function(el, klass) { if (el.classList) { el.classList.add(klass); } else { var attr = el.getAttribute("class") || ""; el.setAttribute("class", attr + " " + klass); } }, removeClass : function(el, klass) { if (el.classList) { el.classList.remove(klass); } else { var attr = el.getAttribute("class") || ""; var regex = new RegExp(klass, "g") el.setAttribute("class", attr.replace(regex, "")); } }, get : function(elemId) { return document.getElementById(elemId); }, find : function(selector) { return document.querySelectorAll(selector); }, append :function(el, html) { var insertFn = my.removeToInsertLater(el); el.innerHTML += html; insertFn(); }, prepend : function(el, html) { var content = el.innerHTML; el.innerHTML = html + content; }, removeToInsertLater : function(element) { var parentNode = element.parentNode; var nextSibling = element.nextSibling; parentNode.removeChild(element); return function() { if (nextSibling) { parentNode.insertBefore(element, nextSibling); } else { parentNode.appendChild(element); } }; } }; </script> <div class="container"> <div id="foobar"> stuff </div> </div> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) window.dataArray = []; for (var i = 0; i < 20; i++) { window.dataArray.push("value " + i); } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) $(".container").html("<div id=\"foobar\">stuff</div>"); Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var elems = my.find(".container"); my.each(elems, function(el) { my.addClass(el, "dumdum"); }); var foobar = my.get("foobar"); my.each(dataArray, function(item, index) { my.append(foobar, "<span>" + item + "</span>"); my.addClass(foobar, index); }); Test 2 Title Async (check if this is an asynchronous test) Code $(".container").addClass("dumdum"); var foobar = $("#foobar"); $.each(dataArray, function(index, item) { foobar.append("<span>" + item + "</span>"); foobar.addClass(index); });