Skip to content

Commit 81240e0

Browse files
committed
add content to Element paragraph
1 parent 2faaf59 commit 81240e0

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

docs/user-guide.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,15 +960,15 @@ standard HTML DOM query selectors to [locate DOM elements](https://developer.moz
960960

961961
Following, we'll look into each one of these aspects a bit more in detail.
962962

963-
##### Element
963+
#### Element
964964

965965
`pydom` `Element` is simply just an abstraction of a tranditional `Element` in a web page.
966966
Every `Element` always maps to an underlying `JavaScript` `Element` in a web page. These 2
967967
elements are always in sync and any change of state in one is reflect into the other.
968968

969969
__ADD DIAGRAM HERE__
970970

971-
###### Creating a new element
971+
##### Creating a new element
972972

973973
New elements can be created by using the `pydom.create` method and passing the type of element
974974
being crated. Here's an example of what it looks like:
@@ -991,14 +991,62 @@ pydom['#element-creation-example'][0].append(new_div)
991991
```
992992

993993
<div>
994-
<h3>Result will go here</h3>
994+
<h5>Result will go here</h5>
995995
<div id="pydom-element-createion-example"></div>
996996
</div>
997997

998998

999999
For more details about `pydom.create` please refer to its reference documentation.
10001000

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+
10021050
## Workers
10031051

10041052
Workers run code that won't block the "main thread" controlling the user

0 commit comments

Comments
 (0)