Javascript objects and loops optimization
<p>So what is the best way to clean up this javascript code (see fiddle link in comments).</p>

<p>By "clean up" I mean replace "document.getElementById..." and fix the output variable to be a reusable function instead of the way I have it there. Two problems I'm having below:</p>

<p>1) When I use .empty then .append for </p>

<p>Currently using:</p>

<pre><code>document.getElementById("results").innerHTML=savedList[keyword];
</code></pre>

<p>Tried using:</p>

<pre><code>$("#results").empty();
$("#results").append(output);
</code></pre>

<p>The output variable isn't defined yet when the list has been cached so that only works for new searches.</p>

<p>2) Creating a function (ie function ABC(data) {...}) outside of the ajax call doesn't let me call the JSON returned data and use it (ie '+ data.repositories[i].followers +'). So not sure how to call that data outside of the ajax request. Ideally I would like to have a function that runs after a successful return that I can just call instead of running all of that inside the success return. (ie success: function(data) {functionToRun();})</p>

<p>I'm looking to optimize the code and learn better ways to make my code more reusable. Any insight is appreciated, thanks!</p>
