Deselect contenteditable element

后端 未结 3 440
臣服心动
臣服心动 2021-01-28 15:05

I am trying to remove selection inside a contenteditable field. The code I have is this:

Text

3条回答
  •  情深已故
    2021-01-28 15:52

    here is the working code

    $(document).ready(function() {
      $('h1').focus();
      document.execCommand('selectAll', false, null);
    })
    
    $("#deselect").click(function(){
            window.getSelection().removeAllRanges();
      });
    

    https://jsfiddle.net/v73e3xdf/2/

提交回复
热议问题