confusion about .html() and .append() when I'm trying to overwrite elements in a loop <p>Sorry about the gory title. Effectively I'm trying to loop through a 2 dimensional array and I'm using autocomplete to output every time a single character is changed. If I use <code>.append</code> or <code>.prepend</code> then I have a long list of characters and that's not quite what I want, I'd like to overwrite every character change so that I'm not stuck with 50 results. I tried using <code>.html</code> and while it works to some extent (it overwrites) it only outputs the last element in the 2 dimensional array, which isn't quite what I want since I'd like to output all elements in the array.</p> <p>Here is my code: </p> <pre><code>for(var i = 0, len = data[1].length; i &lt; len; i++) { var currentDesc = data[2][i]; if(currentDesc.indexOf("may refer to:") &lt;= -1) { $('#results').append('&lt;div id="allResults"&gt;&lt;a href="'+ data[3][i] +'"&gt;'+ data[1][i] +'&lt;/a&gt;&lt;div id="descResults"&gt;'+ data[2][i] +'&lt;/div&gt;&lt;/div&gt;'); } } </code></pre> <p>Any ideas? I've just tried <code>.html()</code>, <code>.append</code>, and <code>.prepend</code></p>