Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following will add a <code>&lt;br&gt;</code> when the enter key is pressed in all major browsers and attempts to place the caret directly after it. However, WebKit, Opera and IE all have issues with placing the caret correctly after the <code>&lt;br&gt;</code>, which the following code does not attempt to correct.</p> <pre><code>function enterKeyPressHandler(evt) { var sel, range, br, addedBr = false; evt = evt || window.event; var charCode = evt.which || evt.keyCode; if (charCode == 13) { if (typeof window.getSelection != "undefined") { sel = window.getSelection(); if (sel.getRangeAt &amp;&amp; sel.rangeCount) { range = sel.getRangeAt(0); range.deleteContents(); br = document.createElement("br"); range.insertNode(br); range.setEndAfter(br); range.setStartAfter(br); sel.removeAllRanges(); sel.addRange(range); addedBr = true; } } else if (typeof document.selection != "undefined") { sel = document.selection; if (sel.createRange) { range = sel.createRange(); range.pasteHTML("&lt;br&gt;"); range.select(); addedBr = true; } } // If successful, prevent the browser's default handling of the keypress if (addedBr) { if (typeof evt.preventDefault != "undefined") { evt.preventDefault(); } else { evt.returnValue = false; } } } } var el = document.getElementById("your_editable_element"); if (typeof el.addEventListener != "undefined") { el.addEventListener("keypress", enterKeyPressHandler, false); } else if (typeof el.attachEvent != "undefined") { el.attachEvent("onkeypress", enterKeyPressHandler); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload