Search code examples
javascriptcursor

How can you display a blinking cursor?


I'm thinking about writing a full screen HTML/CSS/JavaScript editor for the browser so that a user can write their programs directly to the server without having to do the Dreamweaver local view/remote server Dosey Doe. I would need to display a cursor just like what you see in a normal textarea or an input field.

Q: How can you display a blinking cursor?


Solution

  • Set contenteditable on your HTML element. Clicking inside any element with that attribute will give the system's default blinking cursor.

    <div contenteditable>
      The content in this DIV is editable and clicking on it will show a blinking cursor.
    </div>
    

    Docs: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_Editable