 <p>Instead of duplicating the code as you showed, just <a href="http://api.jquery.com/trigger/" rel="nofollow">trigger a click</a> by adding <code>.trigger('click')</code> to what you have when the document loads:</p> <pre><code>$(function() { $('button').click(function() { $.get('teas.txt', function(data) { var teas = data.split('\n'); random = teas[Math.floor(Math.random() * teas.length)]; $('p').text(random); }); }).trigger('click'); }); </code></pre>