Ben Aston Ben Aston - 8 months ago 36
Javascript Question

Sending arguments when focussing an element

I am focussing an element in the DOM like so:


Presumably this is firing a focus event under the hood? Can I supply arguments with this by using a different syntax?

I have tried the following without success. I can use jQuery if need be:

type: "focus",
options: 'argument1',

The handler is bound using angular

<input type="text" ng-focus="onFocus($event)"/>

The handler function:

function onFocus(evt) {
// I want to be able to distinguish events via state I pass


When using jQuery you can use

$('selector').trigger('event',[param1, param2,...])

and catch those with

$('selector').on('event', function(e, param1, param2, ..){..}

(as mentioned in

Unfortunately this will not work with the focus event as documented in this bug report: Extra parameters are not passed when triggering focus

(note: it works in 1.8.3 and below, as mentioned in a linked/relevant bug report: focus event ignores additional data when triggered)