@@ -49,7 +49,7 @@ const $ = cheerio.load(
49
49
);
50
50
51
51
const listItems = $ (' ul' ).find (' li' );
52
- render (` List item count: $ {listItems .length } ` );
52
+ render (<> List item count: {listItems .length }< / > );
53
53
```
54
54
55
55
### ` children `
@@ -70,7 +70,7 @@ const $ = cheerio.load(
70
70
);
71
71
72
72
const listItems = $ (' ul' ).children (' li' );
73
- render (` List item count: $ {listItems .length } ` );
73
+ render (<> List item count: {listItems .length }< / > );
74
74
```
75
75
76
76
### ` contents `
@@ -90,7 +90,7 @@ const $ = cheerio.load(
90
90
);
91
91
92
92
const contents = $ (' div' ).contents ();
93
- render (` Contents count: $ {contents .length } ` );
93
+ render (<> Contents count: {contents .length }< / > );
94
94
```
95
95
96
96
## Moving Up the DOM Tree
@@ -115,7 +115,7 @@ const $ = cheerio.load(
115
115
);
116
116
117
117
const list = $ (' li' ).parent ();
118
- render (list .prop (' tagName' ));
118
+ render (<> { list .prop (' tagName' )} < / > );
119
119
```
120
120
121
121
### ` parents ` and ` parentsUntil `
@@ -145,7 +145,12 @@ const ancestors = $('li').parents();
145
145
const ancestorsUntil = $ (' li' ).parentsUntil (' div' );
146
146
147
147
render (
148
- ` Ancestor count (also includes <body> and <html>): ${ ancestors .length } | Ancestor count (until <div>): ${ ancestorsUntil .length } ` ,
148
+ <>
149
+ < p>
150
+ Ancestor count (also includes " body" and " html" tags): {ancestors .length }
151
+ < / p>
152
+ < p> Ancestor count (until " div" ): {ancestorsUntil .length }< / p>
153
+ < / > ,
149
154
);
150
155
```
151
156
@@ -169,7 +174,7 @@ const $ = cheerio.load(
169
174
);
170
175
171
176
const list = $ (' li' ).closest (' ul' );
172
- render (list .prop (' tagName' ));
177
+ render (<> { list .prop (' tagName' )} < / > );
173
178
```
174
179
175
180
## Moving Sideways Within the DOM Tree
@@ -202,7 +207,12 @@ const $ = cheerio.load(
202
207
const nextItem = $ (' li:first' ).next ();
203
208
const prevItem = $ (' li:eq(1)' ).prev ();
204
209
205
- render (` Next: ${ nextItem .text ()} | Prev: ${ prevItem .text ()} ` );
210
+ render (
211
+ <>
212
+ < p> Next: {nextItem .text ()}< / p>
213
+ < p> Prev: {prevItem .text ()}< / p>
214
+ < / > ,
215
+ );
206
216
```
207
217
208
218
## ` nextAll ` , ` prevAll ` , and ` siblings `
@@ -237,7 +247,11 @@ const prevAll = $('li:last').prevAll();
237
247
const siblings = $ (' li:eq(1)' ).siblings ();
238
248
239
249
render (
240
- ` Next All: ${ nextAll .text ()} | Prev All: ${ prevAll .text ()} | Siblings: ${ siblings .text ()} ` ,
250
+ <>
251
+ < p> Next All: {nextAll .text ()}< / p>
252
+ < p> Prev All: {prevAll .text ()}< / p>
253
+ < p> Siblings: {siblings .text ()}< / p>
254
+ < / > ,
241
255
);
242
256
```
243
257
@@ -270,7 +284,12 @@ const $ = cheerio.load(
270
284
const nextUntil = $ (' li:first' ).nextUntil (' li:last-child' );
271
285
const prevUntil = $ (' li:last' ).prevUntil (' li:first-child' );
272
286
273
- render (` Next: ${ nextUntil .text ()} | Prev: ${ prevUntil .text ()} ` );
287
+ render (
288
+ <>
289
+ < p> Next: {nextUntil .text ()}< / p>
290
+ < p> Prev: {prevUntil .text ()}< / p>
291
+ < / > ,
292
+ );
274
293
```
275
294
276
295
## Filtering elements
@@ -303,7 +322,7 @@ const $ = cheerio.load(
303
322
);
304
323
305
324
const secondItem = $ (' li' ).eq (1 );
306
- render (secondItem .text ());
325
+ render (<> { secondItem .text ()} < / > );
307
326
```
308
327
309
328
### ` filter ` and ` not `
@@ -332,7 +351,10 @@ const matchingItems = $('li').filter('.item');
332
351
const nonMatchingItems = $ (' li' ).not (' .item' );
333
352
334
353
render (
335
- ` Matching: ${ matchingItems .text ()} | Non-matching: ${ nonMatchingItems .text ()} ` ,
354
+ <>
355
+ < p> Matching: {matchingItems .text ()}< / p>
356
+ < p> Non- matching: {nonMatchingItems .text ()}< / p>
357
+ < / > ,
336
358
);
337
359
```
338
360
@@ -357,7 +379,7 @@ const $ = cheerio.load(
357
379
);
358
380
359
381
const matchingItems = $ (' li' ).has (' strong' );
360
- render (matchingItems .length );
382
+ render (<> { matchingItems .length } < / > );
361
383
```
362
384
363
385
### ` first ` and ` last `
@@ -384,7 +406,12 @@ const $ = cheerio.load(
384
406
const firstItem = $ (' li' ).first ();
385
407
const lastItem = $ (' li' ).last ();
386
408
387
- render (` First: ${ firstItem .text ()} | Last: ${ lastItem .text ()} ` );
409
+ render (
410
+ <>
411
+ < p> First: {firstItem .text ()}< / p>
412
+ < p> Last: {lastItem .text ()}< / p>
413
+ < / > ,
414
+ );
388
415
```
389
416
390
417
## Conclusion
0 commit comments