Window.find not focusing on textarea

When I use window.find it is not focusing on textarea. The textarea scroll bar does not scroll when selecting with window.find. How do I focus on “Australian brother” in the textarea?

<!DOCTYPE html>
        <textarea id="positivity" cols="50" rows="10" value="">Happiness

    Australian Brother
    Help Brother
            window.addEventListener('load', function () {
            window.find('Australian Brother');
            }, false);

Please use vanilla javascript, and preferably a method supported by android browsers. Thanks in advance.

Hi @manoodin, is it supposed to? According to the MDN it is non-standard anyway, and some browsers might highlight the found text (but not focus the parent element)…

you’d need some combination of indexOf and setSelectionRange.
String.prototype.indexOf() - JavaScript | MDN (
HTMLInputElement.setSelectionRange() - Web APIs | MDN (

Edit: Probably also a little shenanigans if you want to make it also scroll the text box. See JavaScript: Scroll to selection after using textarea.setSelectionRange in Chrome - Stack Overflow

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.