6
6
7
7
1 . [ Show the different ways of selecting an element from DOM] ( #Q1 )
8
8
1 . [ Show the ways to loop over the Nodelist obtained after querying for the elements] ( #Q2 )
9
- 3 . [ Design and Implement a Node Store, which supports DOM element as key] ( #Q3 )
10
- 4 . [ Implement a function to find the closest ancestor with the provided selector] ( #Q4 )
11
- 5 . [ Write a function to find the corresponding node in two identical DOM trees] ( #Q5 )
12
- 6 . [ Write a function to get depth of a given DOM tree] ( #Q6 )
13
- 7 . [ Implement a function to get the root node of a given DOM fragment] ( #Q7 )
14
- 8 . [ Implement a function to get unique tag names in a given DOM tree] ( #Q8 )
15
- 9 . [ Implement a function to check if a given DOM tree has duplicate IDs] ( #Q9 )
9
+ 1 . [ Design and Implement a Node Store, which supports DOM element as key] ( #Q3 )
10
+ 1 . [ Implement a function to find the closest ancestor with the provided selector] ( #Q4 )
11
+ 1 . [ Write a function to find the corresponding node in two identical DOM trees] ( #Q5 )
12
+ 1 . [ Write a function to get depth of a given DOM tree] ( #Q6 )
13
+ 1 . [ Implement a function to get the root node of a given DOM fragment (document.getRootNode() method)] ( #Q7 )
14
+ 1 . [ Implement a function to get the root node of a given DOM fragment] ( #Q8 )
15
+ 1 . [ Implement a function to get unique tag names in a given DOM tree] ( #Q9 )
16
+ 1 . [ Implement a function to check if a given DOM tree has duplicate IDs] ( #Q10 )
16
17
17
18
---
18
19
@@ -50,7 +51,6 @@ Note goes here
50
51
51
52
<br />
52
53
53
-
54
54
#### Q3
55
55
### Design and Implement a Node Store, which supports DOM element as key
56
56
@@ -94,7 +94,6 @@ class NodeStore {
94
94
95
95
<br />
96
96
97
-
98
97
#### Q4
99
98
### Implement a function to find the closest ancestor with the provided selector (Element.closest() method)
100
99
@@ -141,7 +140,6 @@ A.innerHTML = `
141
140
<div >
142
141
</div >`
143
142
144
-
145
143
const B = A .cloneNode (true )
146
144
const node1 = A .querySelector (' #node1' )
147
145
const node2 = A .querySelector (' #node2' )
@@ -172,7 +170,6 @@ const findCorrespondingNode = (rootA, rootB, target) => {
172
170
173
171
<br />
174
172
175
-
176
173
#### Q6
177
174
### Write a function to get depth of a given DOM tree
178
175
@@ -203,13 +200,13 @@ function getHeight (root) {
203
200
}
204
201
```
205
202
203
+ <br >
206
204
207
205
#### Q7
208
206
### Implement a function to get the root node of a given DOM fragment (document.getRootNode() method)
209
207
210
208
- Root node is the topmost parent node of any given DOM fragment
211
209
212
-
213
210
``` js
214
211
/**
215
212
* @param {HTMLElement | null} tree
@@ -229,6 +226,7 @@ function getRootNode (tree) {
229
226
###### References
230
227
- https://javascript.info/dom-navigation
231
228
229
+ <br >
232
230
233
231
#### Q8
234
232
### Implement a function to get unique tag names in a given DOM tree
@@ -258,11 +256,9 @@ function getUniqueTags(root, result = new Set()) {
258
256
###### References
259
257
- https://bigfrontend.dev/problem/get-DOM-tags
260
258
259
+ <br >
261
260
262
- <br />
263
-
264
-
265
- #### Q8
261
+ #### Q9
266
262
### Implement a function to get elements by tag name (document.getElementsByTagName() method)
267
263
268
264
- The getElementsByTagName method of Document interface returns an HTMLCollection of elements with the given tag name.
@@ -295,8 +291,7 @@ function getElementsByTagName(root, tagName) {
295
291
###### References
296
292
- https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName
297
293
298
-
299
- #### Q9
294
+ #### Q10
300
295
### Implement a function to check if a given DOM tree has duplicate IDs
301
296
302
297
- In a given DOM tree, the id on each node has be unique
@@ -325,5 +320,6 @@ function hasDuplicateId(tree, idSet = new Set()) {
325
320
}
326
321
```
327
322
323
+ <br >
328
324
329
325
[[ ↑] Back to top] ( #home )
0 commit comments