When I press Enter the cursor is at beginning of <mark>This
. I want to get the cursor at the beginning of <p>Hi
. How can I achieve this with jQuery?
<div id="summernote" contenteditable="true"> <p>This is first line</p> <p>Hi <u id="text_id" style="cursor:pointer;"><mark>This is underlined</mark></u> This is second line<br></p> </div>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="summernote" contenteditable="true">
<p>This is first line</p>
<p>Hi <u id="text_id" style="cursor:pointer;"><mark>This is underlined</mark></u> This is second line<br></p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).on("click","#text_id",function() {
var el = document.getElementById("summernote");
var range = document.createRange();
var sel = window.getSelection();
range.setStart(el.childNodes[3], 0);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
el.focus();
});
</script>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.