10 examples of 'get parent element js' in JavaScript

Every line of 'get parent element js' 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
564public getParent(): Element | undefined {
565 const container = this.getContainer();
566
567 if (!container || this.role === Types.ElementRole.Root) {
568 return;
569 }
570
571 const containerParentId = container.getParentElementId();
572
573 if (!containerParentId) {
574 return;
575 }
576
577 return this.project.getElementById(containerParentId);
578}
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

1function _getParentElement() {
2 var parent = this.parentNode;
3 if (parent == null) {
4 return null;
5 }
6 if (parent.nodeType === Node.ELEMENT_NODE) {
7 return parent;
8 }
9 return null;
10}
256_proto._getParent = function _getParent() {
257 var _this3 = this;
258
259 var parent = null;
260
261 if (Util.isElement(this._config.parent)) {
262 parent = this._config.parent; // it's a jQuery object
263
264 if (typeof this._config.parent.jquery !== 'undefined') {
265 parent = this._config.parent[0];
266 }
267 } else {
268 parent = $(this._config.parent)[0];
269 }
270
271 var selector = "[data-toggle=\"collapse\"][data-parent=\"" + this._config.parent + "\"]";
272 $(parent).find(selector).each(function (i, element) {
273 _this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]);
274 });
275 return parent;
276};
144function getParentElement(el: any) {
145 if (el.parentElement ) {
146 // normal element with a parent element
147 return el.parentElement;
148 }
149 if (el.parentNode && el.parentNode.host) {
150 // shadow dom's document fragment
151 return el.parentNode.host;
152 }
153 return null;
154}
16export function getParent(element, level = 0) {
17 let iteration = -1;
18 let parent = null;
19 let elementToCheck = element;
20
21 while (elementToCheck !== null) {
22 if (iteration === level) {
23 parent = elementToCheck;
24 break;
25 }
26
27 if (elementToCheck.host && elementToCheck.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
28 elementToCheck = elementToCheck.host;
29
30 } else {
31 iteration += 1;
32 elementToCheck = elementToCheck.parentNode;
33 }
34 }
35
36 return parent;
37}
63export function isParent(element: SModelElementSchema | SModelElement):
64 element is SModelElementSchema & { children: SModelElementSchema[] } {
65 const children = (element as any).children;
66 return children !== undefined && children.constructor === Array;
67}
308_proto._getParent = function _getParent() {
309 var _this3 = this;
310
311 var parent = null;
312
313 if (Util.isElement(this._config.parent)) {
314 parent = this._config.parent; // It's a jQuery object
315
316 if (typeof this._config.parent.jquery !== 'undefined') {
317 parent = this._config.parent[0];
318 }
319 } else {
320 parent = document.querySelector(this._config.parent);
321 }
322
323 var selector = "[data-toggle=\"collapse\"][data-parent=\"" + this._config.parent + "\"]";
324 var children = [].slice.call(parent.querySelectorAll(selector));
325 $$$1(children).each(function (i, element) {
326 _this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]);
327 });
328 return parent;
329};
4function getParentForm(element) {
5 while (element && element.tagName.toLowerCase() != "form") {
6 element = element.parentNode;
7 }
8 return element;
9}
73function _getParentElement (target) {
74 var element;
75 if (_isDOMElement(target)) {
76 element = target;
77 }
78 else if (_isString(target)) {
79 element = document.querySelector(target);
80 }
81
82 return element;
83}
214export function getSelectParent (child) {
215 const parent = nativeMethods.nodeParentNodeGetter.call(child);
216
217 return closest(parent, 'select');
218}

Related snippets