Mike
Mike

Reputation: 3418

Trigger an event on click within body area

I need to trigger the click, on click on my webpage. I tried the below and it triggers the click onload and not on click.

$(function() { 
            $("body").click(function(e) {

                    alert("code");

            })
            $('#container').trigger('click');
        });

Basically I need to show a popup on click of P keyword from keyboard. While I started I got stuck during the initial stages. Not sure how to achieve this.

Upvotes: 0

Views: 160

Answers (1)

VisioN
VisioN

Reputation: 145398

I guess you need a keydown event where P key passes ASCII code 80:

$("body").on("keydown", function(e) {
    if (e.which === 80) {
        alert("'p' was pressed");
    }
});

Upvotes: 2

Related Questions