-1

I want to generate keyup event with <th>. If i click in <th> click event is populating there but my requirement is generate event when i release CTRL key pressed with click in <th> area I am using the following code

<html>
<head>
<script
 src="https://code.jquery.com/jquery-3.2.1.min.js"
 integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
 crossorigin="anonymous"></script>
</head>
<body>
<table border="2">
<th>rollno</th>
<th>name</th>
<tr>
<td>4567</td>
<td>john</td>
 </tr>
</table>
 </body>
 <script>
 $('th').click(function(){
 alert("yes its working");
 });
 </script>
 <script>
 $('th').on('keyup', function(e) {
 if (e.keyCode ==17)
 {
 alert("OOps! ctr+click release not working");
 }  
 });
 </script>

 </html>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
adesh singh
  • 1,727
  • 9
  • 38
  • 70

2 Answers2

0

Like that ?

$('th').click(function(e){
    if(e.ctrlKey){
        alert("yes its working");
    }
});

EDIT :

$( 'th' ).click( function ( e ) {

    if ( e.ctrlKey ) {

        $( window ).on( 'keyup' , function () {

            alert( "yes its working" );

            $( window ).off( 'keyup' );

        } );

    }
    else {
        alert( 'nop' );
    }

} );
0
$(document).on('keyup',function(event){
 if(event.which=="17"){
    cntrlIsPressed = true;
}
else{cntrllsPressed=false;}
});
 $('th').on('click ', function(e) {
 if (cntrllsPressed==true)
 {
 alert("OOps! ctr+click release not working");
}
});
$(document).on('keydown',function(event){
    cntrlIsPressed =false;
});
Osama
  • 2,912
  • 1
  • 12
  • 15