Something like this:
$(document).ready(function() {
var $text = $("textarea.textarea"),
$btn = $("input.submit");
$(document).click(function(e) {
if (!$text.is(e.target) && !$btn.is(e.target) && $text.val() == "")
$btn.hide();
else
$btn.show();
});
});
That is, bearing in mind that click events bubble up to the document but you can still determine the originally clicked element with event.target
, on any click event that the document receives test whether the click was somewhere other than the textarea or button, and if so and the textarea is empty hide the button, otherwise show it.
Demo: http://jsfiddle.net/HpmDF/
Note that using classes to identify individual controls isn't the best plan, that's what id is for. If there can be more than one textarea and associated button you'll need a different solution.
P.S. Note also that you asked explicitly about "clicks" and that's what I've provided, but you need to allow for the user tabbing out via the keyboard...