@@ -960,15 +960,15 @@ standard HTML DOM query selectors to [locate DOM elements](https://developer.moz
960
960
961
961
Following, we'll look into each one of these aspects a bit more in detail.
962
962
963
- ##### Element
963
+ #### Element
964
964
965
965
` pydom ` ` Element ` is simply just an abstraction of a tranditional ` Element ` in a web page.
966
966
Every ` Element ` always maps to an underlying ` JavaScript ` ` Element ` in a web page. These 2
967
967
elements are always in sync and any change of state in one is reflect into the other.
968
968
969
969
__ ADD DIAGRAM HERE__
970
970
971
- ###### Creating a new element
971
+ ##### Creating a new element
972
972
973
973
New elements can be created by using the ` pydom.create ` method and passing the type of element
974
974
being crated. Here's an example of what it looks like:
@@ -991,14 +991,62 @@ pydom['#element-creation-example'][0].append(new_div)
991
991
```
992
992
993
993
<div >
994
- <h3 >Result will go here</h3 >
994
+ <h5 >Result will go here</h5 >
995
995
<div id =" pydom-element-createion-example " ></div >
996
996
</div >
997
997
998
998
999
999
For more details about ` pydom.create ` please refer to its reference documentation.
1000
1000
1001
-
1001
+ ##### Setting the content of an element
1002
+
1003
+ The Element interface offers 2 main ways to set an element content: the ` html ` and the
1004
+ ` content ` attributes:
1005
+
1006
+ * ` content ` : sets the ` innerHTML ` field via the PyScript ` display ` function. This takes care
1007
+ of properly rendering the object being passed based on the object mimetype. So, for instance,
1008
+ if the objects is an image, it'll be properly rendered on the element
1009
+ * ` html ` : directly sets the ` innerHTML ` field of the underlying element without attemnpting
1010
+ any conversion.
1011
+
1012
+ In general, we suggest using ` content ` directly as it'll take care of most use cases without
1013
+ requiring any extra logic from the user.
1014
+
1015
+ ##### Changing the element style
1016
+
1017
+ Elements have a ` style ` attribute that can be used to change the element style rules.
1018
+ The style attribyte can be used as a dictionary and, to set a style rule for the element,
1019
+ simply set the correct key on the ` .style ` attribute. For instance, the following
1020
+ code changes the background color of the element just created in the example above:
1021
+
1022
+ ``` python
1023
+ new_p.style[" background-color" ] = " yellow"
1024
+ ```
1025
+
1026
+ to remove a specific style key, simply use the ` pop ` method as you'd to to remove
1027
+ a key from a dictionary:
1028
+
1029
+ ``` python
1030
+ new_p.style.pop(" background-color" )
1031
+ ```
1032
+
1033
+ In addition to the dictionary interface to explicitly set CSS rules, the ` style ` attribute
1034
+ also offers a convenient ` visible ` property that can be use show/hide an element.
1035
+
1036
+ ``` python
1037
+ new_p.style.visible = False
1038
+ ```
1039
+
1040
+ ##### Other useful aspects of the Element API
1041
+
1042
+ ` append ` : method to append a new child to the element.
1043
+ ` children ` : list of the children of the element.
1044
+ ` value ` : allows to set the ` value ` attribute of an element.
1045
+ ` clone ` : method that creates a clone of the element. NODE: The clone elements will not be
1046
+ attached to any element.
1047
+ ` show_me ` : method to scroll the page to where the element is placed.
1048
+
1049
+
1002
1050
## Workers
1003
1051
1004
1052
Workers run code that won't block the "main thread" controlling the user
0 commit comments