How to check if button is clicked while text input has focus using jQuery <p>I'm relatively new to code and have been building a little project called <a href="http://keyboardcalculator.com/" rel="nofollow">http://keyboardcalculator.com/</a> to improve my jQuery.</p> <p>I'm trying to add some more features to improve some things - and I've coded them! - but I want to add a button at the bottom of the page that displays a div to tell people what they are. </p> <p>I don't want to tarnish the user flow when the button is clicked - and a big part of that for me is that I don't want the user to have to click back into one of the text-input boxes to keep doing calculations. </p> <p>I want the focus to go back onto the last text-input that the user had focus on. This is my attempt to get it working on the #ansinput text-input field (the big one with the answer in):</p> <pre><code>if ($('#ansinput').is(':focus')) { $('#more-commands-button').click(function() { alert('hello') }); } </code></pre> <p>But I'm not getting my alert. </p> <p>Any help as where to go from here would be fantastic!</p> <p>Thank you very much StackOverflow!</p>