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

  • SEARCH
  • Home
  • 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 8175237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:42:37+00:00 2026-06-06T22:42:37+00:00

When I try to do .focus() I expect to set focus on input element

  • 0

When I try to do .focus() I expect to set focus on input element and to see cursor after last character of the value. And I see it in IE.

In safari/chrome input gets focus and all text is selected.
In firefox/opera input gets focus, but cursor is in the beginning.

What could I do to prevent that and get correct behavior for all browsers?

An example is here: http://jsbin.com/ozojol/edit#javascript,html

PS. focus().val('').val(value) method doesn’t work in IE… What other workarounds exist?

  • 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-06-06T22:42:39+00:00Added an answer on June 6, 2026 at 10:42 pm

    You can use the input’s selectionStart and selectionEnd properties in most browsers and some nasty TextRange stuff in IE < 9. Here’s some code adapted from an answer to a similar question.

    Demo: http://jsbin.com/azapuy

    Code:

    function moveCaretToEnd(el) {
        if (typeof el.selectionStart == "number") {
            el.selectionStart = el.selectionEnd = el.value.length;
        } else if (typeof el.createTextRange != "undefined") {
            var range = el.createTextRange();
            range.collapse(false);
            range.select();
        }
    }
    
    var input = $('#i')[0];
    input.focus();
    moveCaretToEnd(input);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently facing the problem that when i try to set focus on some
Here is my code: jQuery('span.con').delegate('input#sdate', 'focus', function(e){ try { var oneDay = 24*60*60*1000; rangeConv
$('#searchBox input').focus(function(){ console.log(true); $('nav').addClass('searching'); }); $('#searchBox input').blur(function(){ console.log(false) $('nav').removeClass('searching'); }); this works fine: adds
Based on my dataset row value , my drop drown will focus the particular
My goal is to set the focus to a specific inputText. As there seems
Setting focus on a form element using JavaScript is usually very straight forward. I
With the following code I try to give an a element autofocus when the
try: F2 start editing and ENTER stop editing and the focus switches to the
So I try: <html> <head> </head> <body> <script> window.onblur = function() { window.focus(); };
I have some TextBox on focus ( cursor is blinking on him ). Now,

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.