Search code examples
javascriptjquery

Dynamically focus out blur contenteditable


http://codepen.io/anon/pen/rhnuE

I'm using JS Hotkeys from - https://github.com/jeresig/jquery.hotkeys

What I'm trying to do is deselect/focusout a focused contenteditable element. I also want the default focus dotted line to be removed when you click out of the element all called from the [Esc] key when pressed.

$(document).ready(function() {
  // Shortcut to deselect element
  $(document).bind('keydown', 'esc', function() {
    $('.box').focusout();
  });
});

Solution

  • Try using

    $('.box').blur()
    

    instead of focusout() it works fine for me.

    $(document).ready(function() {
      $(document).keyup(function(e) {
      if (e.keyCode == 27) { // Key 27 is the same as Esc
        $('#formId').blur();
      }
     });
    });