-2

I have something like this:

$(".BWTabVerticalTitle").on("click", function () { alert('You pressed enter!'); });

and something like this:

        $(".BWTabVerticalTitle").keypress(function (e) {
            if (e.which == 13) {
                alert('You pressed enter!');
            }
        });

Now, I would like to combine these 2, to one statement which calls that function. May be something like this:

        $(".BWTabVerticalTitle").on("click", function (e) {
        if (e.which == 13) {
            alert('You pressed enter!');
        }
        }).keypress();

The goal is to activate the function whith the ENTER-key and a click event, but my idea does not work...

Thanks...

user254197
  • 833
  • 1
  • 7
  • 29

1 Answers1

2
 $(".BWTabVerticalTitle").bind('click keydown', function(e) {
     if (e.which === 13) {
        alert('enter!')
     }
     else { alert('click') }
});
bencripps
  • 1,999
  • 3
  • 16
  • 27