keydown/keyup toggle functionality

keydown/keyup toggle functionality

I'm trying to understand how I might toggle on/off functionality while a key is pressed. I've been working on an example but I'm struggling with how to select the element I'm currently interacting with so I can revert functionality once the key is released.

Below is the code I'm currently working on. On lines 6, 16 and 17 I would really like to select the specific element that was being resized, not all items in that class. How can I reference that specific item to toggle it's settings?

  1. $(document).keydown(function(e) {
  2.       var keyCode = e.keyCode || e.which; 
  3.       if (keyCode == 18){
  4.   
  5.             $(".onpage").resizable({
  6.                   alsoResize: false,
  7.                   aspectRatio: false
  8.             });      
  9.       }
  10. });

  11. $(document).keyup(function(e) {
  12.       var keyCode = e.keyCode || e.which; 
  13.       if (keyCode == 18){
  14.             $(".onpage").resizable({
  15.                   alsoResize: $(".onpage").find('img'),
  16.                   aspectRatio: true
  17.             });
  18.       }
  19. });

Thanks,

Dave