Callback function issue jquery <p>I have an issue with an if in a callback function and I don't understand why.</p> <p>After clicking on a div, the text is changing as I would like, but after the first shot it doesn't work anymore.</p> <p>My code is :</p> <pre><code>&lt;div id="2"&gt;message&lt;/div&gt; &lt;div id="1"&gt;dfdfgdfgrr&lt;/div&gt; &lt;script src="jquery.js"&gt;&lt;/script&gt; &lt;script&gt; $(function () { $('#2').toggle(); function test() { $(document).on('click', '#1', function () { $('#2').toggle(300, function() { if($('#1').text('show')){ $('#1').text('hide'); }else{ $('#1').text('show'); } }); }); } test(); }); &lt;/script&gt; </code></pre> <p><a href="http://jsfiddle.net/manguo_manguo/cydjY/" rel="nofollow">http://jsfiddle.net/manguo_manguo/cydjY/</a></p>