I second user1777136's suggestion of not appending to the DOM in a loop.
Additional suggestions:
Get rid of your
setTimeoutfunction. Instead, create a$(document).readyhandler and prepend your instructions to thebody.Change your
keypresshandler to$('#search').change, which would also go inside$(document).ready. Perform input validation inside the handler to simplify yourgitSearchfunction:// Get the value from the search field $('#search').change(function(e) { if (!$(this).val()) { alert("Please enter a term to search for"); } else { gitSearch($(this).val()); } });Instead of having individual
clicklisteners defined inside theeachloop, store the data for each element and retrieve it with a delegated listener in$(document).ready:$('#results').on('click', 'li', function(event) { alert("Repo Language is : " + $(this).data('language') + "\n" + "There are " + $(this).data('followers') + " followers of this repo.\n" + "The URL of the repo is : " + $(this).data('url') + "\n" + "The description of the repo : " + $(this).data('description')); });Keep one string containing all your CSS, including the styles for your
li's; you don't need inline CSS for these and this will remove the need forhoverlisteners. So in addition to your body styles you'd havestyles += "#results li { cursor: pointer; list-style-type: none; color: #fff; }"; styles += "#results li:hover { color: #000; }";