Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1095973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:12:37+00:00 2026-05-17T00:12:37+00:00

How do I set the cursor on a div-element in javascript? I have a

  • 0

How do I set the cursor on a div-element in javascript?

I have a form(div-element not input) with a textstring attached on it. I want the textstring removed and the cursor set at the beginning of the element onclick.

I have removed the content in the div-element with onclick event with: divElement.innerHTML = '';

Now I want the cursor to be set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:12:38+00:00Added an answer on May 17, 2026 at 12:12 am

    If by ‘cursor’, you mean the text cursor (aka the caret), I presume what you’re really asking is how to make a div into an editable content box.

    What you need is to set the contentEditable attribute on your div.

    If you want it editable from the start, just include it in your HTML code:

    <div contentEditable="true">....</div>
    

    If you want to switch it on/off, you can set it in javascript:

    mydiv.contentEditable="true"
    

    However, the only time I can think of when it’s better to use contentEditable rather than a textarea is if you’re writing a WYSIWYG HTML editor.

    Most of the rest of the time I would say it’s probably preferable to use a <textarea>. You can style it to look like the rest of your page, and you can make it readonly or disabled when you don’t want it changed. But it is much easier to work with in a form and in Javascript. The problem with using a div is that it can contain other html tags, which may affect how it works, and will likely open you up to security problems if you make it directly editable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a draggable div to which I want to set containment 80% of
I have some problem with the cursor when using JOprionPane. I set a cursor
I have a form that I want to be used to add entries. Once
basically I have 4 images with divs set up like this: <div id=selector> <div
I have ScrollPanel in UI. And I want to dynamically change cursor over this
I have logic to insert a tag in a contenteditable div. I want to
Possible Duplicate: CKEditor - Set cursor position to end of text I have a
I have the 'Line-height' attribute set to .8 which affects any text within <div
I want to capture the cursor coordinates over an image in a modal form
I used setCursor() method to set a cursor for JTable. But that cursor is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.