File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Loops through a list of nodes to check if it contains a specific tag name (or names).
3
+ *
4
+ * @param {NodeList } nodeList - A list of nodes in the DOM tree.
5
+ * @param {(string|string[]) } tags - A tag name or a list of tag names.
6
+ * @returns {Boolean } - True if list contains any of the specified tags.
7
+ */
8
+
9
+ export function containsTagName ( nodeList , tags ) {
10
+ let hasElement = false ;
11
+
12
+ if ( typeof tags === 'string' ) {
13
+ tags = [ tags ] ;
14
+ } else if ( ! Array . isArray ( tags ) ) {
15
+ return null ;
16
+ }
17
+
18
+ tags = tags . map ( name => name . toUpperCase ( ) ) ;
19
+
20
+ nodeList . forEach ( ( childElement , i ) => {
21
+ if ( childElement . tagName && tags . includes ( childElement . tagName ) ) {
22
+ hasElement = true ;
23
+ }
24
+ } ) ;
25
+
26
+ return hasElement ;
27
+ }
Original file line number Diff line number Diff line change 1
1
export * from './color-contrast' ;
2
2
export * from './contains-any' ;
3
+ export * from './contains-tag-name' ;
3
4
export * from './css' ;
4
5
export * from './declarative-click-handler' ;
5
6
export * from './environment' ;
You can’t perform that action at this time.
0 commit comments