manu
manu

Reputation: 1017

How can I find the element that caused another element to fire the focusout event?

i bind an eventhandler to the focusout-event of my text-inputfield. this handler hides a div with some searchresults as soon as the inputfield losts its focus.

following my markup and a screenshot of the situation:

<li class="search">
    <input type="text" id="searchbox" />
    <div id="results">
        <ol>
            <li>...</li>
        </ol>
    </div>
</li>

enter image description here

when the user clicks on a item in the searchresults now, the inputfield fires the focusout event as desired. i expected to be able extracting the element which gets the focus as next out of the eventobject. unfortunatly this seems not to be possible since only (some) mouse-events fill in the relatedTarget-property of the event.

is there any easy way to get the element which gains focus next?

Upvotes: 4

Views: 1308

Answers (1)

entropo
entropo

Reputation: 2481

Would this help you? http://plugins.jquery.com/project/focused

Not in older browsers, but there's document.activeElement too: https://developer.mozilla.org/en/DOM/document.activeElement

Upvotes: 2

Related Questions