getNearest

caph.focus.nearestFocusableFinder. getNearest

Gets the DOM element closest to the specific direction of the given element.

(static) getNearest(target, direction) → {DOMElement}

Parameters:
Name Type Description
target DOMElement | jQuery

The base element.

direction string

The direction to search for.

Returns:

If there is no nearest element, returns null.

Type
DOMElement
Example
angular.module('myApp', ['caph.focus']).controller('myController', ['$scope', 'FocusConstant', 'focusController', 'nearestFocusableFinder', function($scope, FocusConstant, focusController, nearestFocusableFinder) {
 	$scope.focusRight = function(from) {
 		focusController.focus(nearestFocusableFinder.getNearest(from, FocusConstant.DIRECTION.RIGHT));
 	}
 }]);