Try this:
$('div[contenteditable]').keydown(function(e) {
// trap the return key being pressed
if (e.keyCode === 13) {
// insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
document.execCommand('insertHTML', false, '<br/>');
// prevent the default behaviour of return key pressed
return false;
}
});
Click here for demo
Related Contents:
- contenteditable change events
- Set cursor position on contentEditable
- Jquery load() only working in firefox?
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- JSFiddle code not working in my own page
- Chrome Extension how to send data from content script to popup.html
- How can I remove the “No file chosen” tooltip from a file input in Chrome?
- How can I retain the scroll position of a scrollable area when pressing back button?
- Proper way to reset a GIF animation with display:none on Chrome
- jQuery in Chrome returns “block” instead of “inline”
- Chrome Extension “Refused to load the script because it violates the following Content Security Policy directive”
- How to send FormData objects with Ajax-requests in jQuery? [duplicate]
- Event on a disabled input
- Clearing using jQuery
- How to scroll an HTML page to a given anchor
- contenteditable, set caret at the end of the text (cross-browser)
- Difference between val() and text()
- How do I create a link using javascript?
- Finding line-wraps
- Clear icon inside input text
- Force a browser to save file as after clicking link [duplicate]
- Show and hide divs at a specific time interval using jQuery
- Limit number of lines in textarea and Display line count using jQuery
- How to get nth-child selector to skip hidden divs [duplicate]
- How can I sort elements by numerical value of data attribute?
- Integrating Dropzone.js into existing HTML form with other fields
- Check Ctrl / Shift / Alt keys on ‘click’ event
- Change text color based on brightness of the covered background area?
- Generic way to detect if html form is edited
- make html text input field grow as I type?
- Chrome Autofill/Autocomplete no value for password
- Dropdown select with images
- Sort an html list with javascript
- Disable dragging an image from an HTML page
- Prevent browser from loading a drag-and-dropped file
- Set keyboard focus to a
- Chrome FileReader
- How to write into a file (in user directory) using JavaScript?
- Retrieving file names out of a multi-file upload control with javascript
- Creating a select box with a search option
- Selecting multiple from an html select element without using ctrl key
- How to convert html table to excel with multiple sheet?
- Counting and limiting words in a textarea
- How to focus on a form input text field on page load using jQuery?
- How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?
- How to bind click event to object tag?
- Drop image into contenteditable in Chrome to the cursor
- combo box is getting vanished when an alert is coming
- HTML5 drop event doesn’t work unless dragover is handled
- How to compare two HTML elements