1

I've been working on sending text to an input element in Chrome and I noticed that, unlike in IE or FF, calling .focus() does not put the cursor in the text area. So does anyone know of an alternative for placing the cursor on a Chrome input element?

1
  • I never had problems triggering focus() on Chrome, could you post some code? Commented May 18, 2010 at 5:05

2 Answers 2

2

I have no issues either. Here is an simple HTML file I have that works in Chrome:

<html>
<body>

<textarea id="ta1"></textarea>
<br />
<textarea id="ta2"></textarea>
<br />
<textarea id="ta3"></textarea>

<script>
document.getElementById("ta2").focus();
</script>

</body>
</html>

Are you putting the script section above or below the textareas?

Sign up to request clarification or add additional context in comments.

Comments

0

Here's some of the code I'm using:

var event = document.createEvent("HTMLEvents");

event.initEvent("focus", true, true);

element.dispatchEvent(event);

1 Comment

Thanks guys, now it's working. Apparently calling dispatchEvent wasn't doing it, but calling .focus() directly does work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.