Initiate click on div using tab and enter

focus, html, javascript, jquery

Solution

You can create a custom event like this:

$("div").on("click enter",function(){
    alert("div click")

})
.on('keypress', function(e) {
    if(e.which === 13) {
        $(this).trigger( 'enter' );
    }
});

DEMO

Problem

I have a and div element ``` <a href="javascript:void(0)">link</a> <div tabindex="0">div</div> ``` And click event handlers ``` $("a").on("click",function(){ alert(" a click") }); $("div").on("click",function(){ alert("div click") }); ``` Using keyboard tab I can navigate to a link ,press Enter and see alert,but I can't do this for div. Is it possible initiate click event for div as same as for a tag,without using any other events(keypress)? JSfiddle

Original source