cursor position

I have an iframe like:

    <iframe id = "ddd"></iframe>

the user can type some text in it when design mode is on.

Is there a function I can use to automatically move the cursor to the end of the iframe?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Samuel LiewCommented:
When you mean cursor, do you mean mouse cursor or text cursor? You definitely can't move the mouse cursor.
You might want a textarea or textbox for that.

But as was suggested, you're asking about the "caret", not the "cursor" ;)

Enjoy! ^^


      <title>Test Page</title>

      <script language="JavaScript" type="text/javascript">
      function runTest()
            var bdy = ddd.document.body;

            if (bdy.createTextRange) {
                  var range = bdy.createTextRange();
                  range.moveEnd('character', bdy.innerHTML.length);
                  range.moveStart('character', bdy.innerHTML.length);


      <input type="button" value="Run Test" onclick="javascript:runTest();">


      <iframe id="ddd" src="iframe.html"></iframe>



      <title>The IFrame</title>

<body contenteditable="true">


<span id="test"></span>



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.