File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -1057,11 +1057,36 @@ paragraphs = pydom['p']
1057
1057
1058
1058
In the example above, ` paragraphs ` is an ` ElementCollection ` that maps to all ` p ` elements in the page.
1059
1059
1060
+ As any collections, ` ElementCollection ` can be used to iterate over a collection of elements or to pick
1061
+ specific elements or slices of elements in the collection. For instance:
1060
1062
1063
+ ``` python
1064
+ for element in paragraphs:
1065
+ display(element.html)
1066
+
1067
+ # let's now display only the last 2 elements
1068
+ for element in paragraphs[- 2 :]:
1069
+ display(element.html)
1070
+ ```
1061
1071
1062
1072
##### Interacting with an ElementCollection
1063
1073
1064
- Interacting
1074
+ Besides from allowing operations as an iterable object, ` ElementCollection ` objects also offer a few
1075
+ convenient methods to directly interact with th elements in the collection. For instance, it's possible
1076
+ to ask for specific attributes of the elements in the collection directly:
1077
+
1078
+ ``` python
1079
+ display(paragraphs.html)
1080
+ ```
1081
+
1082
+ The example above displays a list with the value of the ` html ` attribute for all the elements in the
1083
+ ` paragraphs ` collection.
1084
+
1085
+ The same way we can read attributes, we can also set an attribute directly in the collection. For instance:
1086
+
1087
+ ``` python
1088
+ paragraphs.html = " That's cool :)"
1089
+ ```
1065
1090
1066
1091
1067
1092
## Workers
You can’t perform that action at this time.
0 commit comments