10 examples of 'closest jquery' in JavaScript

Every line of 'closest jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
22export function closest(element: Element, selector: string): Element | null {
23 return closestCallback(element, (el: Element) => matches.call(el, selector))
24}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10function closest(element, selector, top = document.body) {
11 while (!element.matches(selector)) {
12 element = element.parentNode
13 if (element === top) {
14 return null
15 }
16 }
17 return element
18}
45function JQueryClosestByClass(element, clazz) {
46 while (element) {
47 if (JQueryHasClass(element, clazz)) {
48 return element;
49 }
50 element = element.parentNode;
51 }
52 return null;
53}
179function closest(el, selector) {
180 while (el) {
181 if (matches(el, selector)) {
182 return el;
183 } else {
184 el = el.parentElement;
185 }
186 }
187 return false;
188}
260function closest(element, selector) {
261 if (element.closest) {
262 return element.closest(selector);
263 }
264 var el = element;
265 while (el) {
266 if (matches(el, selector)) {
267 return el;
268 }
269 el = el.parentElement;
270 }
271 return null;
272}
12function closest(element, selector) {
13 var matchesFn;
14
15 // find vendor prefix
16 ['matches', 'msMatchesSelector'].some(function(fn) {
17 if (typeof document.body[fn] == 'function') {
18 matchesFn = fn;
19 return true;
20 }
21 return false;
22 })
23
24 var parent;
25
26 // Traverse parents
27 while (element) {
28 parent = element.parentElement;
29 if (parent && parent[matchesFn](selector)) {
30 return parent;
31 }
32 element = parent;
33 }
34
35 return null;
36}
68export function closest (element, selector) {
69 while (element && element.nodeType === 1) {
70 if (matches(element, selector)) {
71 return element
72 }
73
74 element = element.parentNode
75 }
76
77 return null
78}
107export function closest(selector, element, check__self) {
108 let __ = check__self
109 ? element
110 : element.parentNode
111 while (__ && __ !== document) {
112 if (matches(__, selector)) return __
113 __ = __.parentNode
114 }
115}
71export function closest(elem, selector) {
72 if (elem.closest) {
73 return elem.closest(selector);
74 }
75 while (elem) {
76 if (matches(elem, selector)) {
77 return elem;
78 }
79 elem = elem.parentElement;
80 }
81 return null;
82}
23function closest(selector, context) {
24 var nodes = [];
25 _util.each(this, function (node) {
26 while (node && node !== context) {
27 if (_index.matches(node, selector)) {
28 nodes.push(node);
29 break;
30 }
31 node = node.parentElement;
32 }
33 });
34 return _index.$(_util.uniq(nodes));
35}

Related snippets