1

Here is what I have:

$(document).ready(function () {
$('#H-Alert').hide();

$('html').click(function (e) {
    if (e.target.className == '.h-textbox') {
        $('#H-Alert').show();
    }
    else {
        $('#H-Alert').hide();
    }
});
});

I have referenced this:

Reference

Any help is appreciated.

Community
  • 1
  • 1
Grizzly
  • 5,873
  • 8
  • 56
  • 109
  • Possible duplicate of [How to detect a click outside an element?](http://stackoverflow.com/questions/152975/how-to-detect-a-click-outside-an-element) – Daniel Werner May 23 '16 at 21:01

2 Answers2

1

You're probably looking for the blur and focus events. You can do this using jQuery as follows:

$('#H-Alert').hide();
$(window).ready(function(){
    $('.h-textbox').blur(function(){
      $('#H-Alert').show();
    }).focus(function(){
      $('#H-Alert').hide();
    });
});
meltuhamy
  • 3,293
  • 4
  • 23
  • 22
  • thank you. that worked. I just changed a few things. `$(document).ready(function () { $('#Hobbs-Alert').hide(); $('.hobbs-textbox').blur(function () { $('#Hobbs-Alert').hide(); }).focus(function () { $('#Hobbs-Alert').show(); }); }); ` – Grizzly May 24 '16 at 12:12
1

For events on entering or leaving textboxes the solution of @meltuhamy may be better, but if you like to work with the events directly, you could use this:

$(document).click(function(event) {
    if($(event.target).closest(".h-textbox").length == 0) {
        if($("#H-Alert").is(":visible")) {
            $("#H-Alert").hide();
        } else {
            $("#H-Alert").show();
        }
    }
});
bohrsty
  • 406
  • 6
  • 17