summaryrefslogtreecommitdiff
path: root/packages/frontend/src/utility/element-contains.ts
blob: 8389d49278c636fcf3a949c7733ce99d678c0142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

export function elementContains(parent: Element | null, child: Element | null, checkSame = true) {
	if (parent === null || child === null) return false;
	if (checkSame && parent === child) return true;
	let node = child.parentNode;
	while (node) {
		if (node === parent) return true;
		node = node.parentNode;
	}
	return false;
}