I was recently working on a comment feature that required the ability to comment on emoticons, so the First, comment on the district chief: When the input content exceeds the limit, clear the content after the user input exceeds the limit. This is easy... But after clearing the content, the cursor actually moved to the front, which is a headache. After various searches, I found a solution. Without further ado, here is the code! var _div = document.querySelector('.discuss_area'); var range = document.createRange(); range.selectNodeContents(_div); range.collapse(false); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); All of them use native events, so This article is about solving the problem that when a div is set to contentEditable=true, the cursor cannot be positioned correctly after resetting its content. This is the end of the article. For more relevant content about div setting contentEditable=true, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Common naming rules for CSS classes and ids
>>: Detailed explanation of CSS background and border tag examples
Most of the earliest computers could only use ASC...
This article records the specific method of insta...
Download Nginx image in Docker docker pull nginx ...
Table of contents Pitfalls encountered in timesta...
The default arrangement of text in HTML is horizo...
The usage format of the mysqladmin tool is: mysql...
This article takes the connection error ECONNREFU...
This article example shares the specific code of ...
Method 1: To use respin, follow these steps: sudo...
A few days ago, a colleague received a points mal...
This method was edited on February 7, 2021. The v...
Newer Linux distributions no longer have the rc.l...
Table of contents 1. Introduction 2. Advantages 3...
<br /> When we browse certain websites and s...
Preface When we write code, we occasionally encou...