@@ -413,6 +413,8 @@ store = await storage("my-data-store", storage_class=MyStorage)
413413
414414### ` pyscript.web `
415415
416+ TODO: Use ` display(element) ` not ` element.display() ` .
417+
416418The classes and references in this namespace provide a Pythonic way to interact
417419with the DOM. An explanation for how to idiomatically use this API can be found
418420[ in the user guide] ( ../user-guide/dom/#pyscriptweb )
@@ -424,14 +426,19 @@ This object has two attributes and a single method:
424426* ` head ` - a reference to a Python object representing the [ document's head] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head ) .
425427* ` body ` - a reference to a Python object representing the [ document's body] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body ) .
426428* ` find ` - a method that takes a single [ selector] ( https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors )
427- argument and returns a collection of matching elements.
429+ argument and returns a collection of Python objects representing the matching
430+ elements.
431+
432+ These are provided as a convenience so you have several simple and obvious
433+ options for accessing the content of the page (DOM).
428434
429- You have several options for accessing the
435+ All the Python objects returned by these attributes and method are instances of
436+ classes defined in the ` pyscript.web.elements ` namespace.
430437
431438#### ` pyscript.web.elements.* `
432439
433440There are many classes in this namespace. Each is a one-to-one mapping of any
434- HTML element name for a Python class representing the HTML element of that
441+ HTML element name to a Python class representing the HTML element of that
435442name. Each Python class ensures only valid properties and attributes can be
436443assigned, according to web standards.
437444
@@ -472,6 +479,9 @@ Usage of these classes is
472479 (`_`) because they are also keywords in Python, and the `grid` is a custom
473480 class for a `div` with a `grid` style `display` property.
474481
482+ All these classes ultimately derive from the
483+ `pyscript.web.elements.Element` base class.
484+
475485In addition to properties defined by the HTML standard for each type of HTML
476486element (e.g. ` title ` , ` src ` or ` href ` ), all elements have the following
477487properties and methods (in alphabetical order):
@@ -482,15 +492,34 @@ properties and methods (in alphabetical order):
482492* ` classes ` - a set of CSS classes associated with the element.
483493* ` clone(clone_id=None) ` - Make a clone of the element (and the underlying DOM
484494 object), and assign it the optional ` clone_id ` .
485- * ` content ` - get or set the
486- [ innerHTML] ( https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML )
487- of the element.
488495* ` find(selector) ` - use a CSS selector to find matching child elements.
489496* ` parent ` - the element's parent element (that contains it).
490497* ` show_me ` - scroll the element into view.
491498* ` style ` - a dictionary of CSS style properties associated with the element.
492499* ` update(classes=None, style=None, **kwargs) ` - update the element with the
493500 specified classes (set), style (dict) and DOM properties (kwargs).
501+ * ` _dom_element ` - a reference to the proxy object that represents the
502+ underlying native HTML element.
503+
504+ !!! info
505+
506+ All elements, by virtue of inheriting from the base `Element` class, may
507+ have the following properties:
508+
509+ ```
510+ accesskey, autofocus, autocapitalize,
511+ className, contenteditable,
512+ draggable,
513+ enterkeyhint,
514+ hidden,
515+ innerHTML, id,
516+ lang,
517+ nonce,
518+ part, popover,
519+ slot, spellcheck,
520+ tabindex, text, title, translate,
521+ virtualkeyboardpolicy
522+ ```
494523
495524The ` classes ` set-like object has the following convenience functions:
496525
@@ -501,8 +530,26 @@ The `classes` set-like object has the following convenience functions:
501530* ` replace(old_class, new_class) ` - replace the ` old_class ` with ` new_class ` .
502531* ` toggle(class_name) ` - add a class if it is absent, or remove a class if it
503532 is present.
504- * ` _dom_element ` - a reference to the proxy object that represents the
505- underlying HTML element.
533+
534+ Elements that require options (such as the ` datalist ` , ` optgroup ` and ` select `
535+ elements), can have options passed in when they are created:
536+
537+ ``` python
538+ my_select = select_(option(" apple" , value = 1 ), option(" pear" ))
539+ ```
540+
541+ Notice how options can be a tuple of two values (the name and associated value)
542+ or just the single name (whose associated value will default to the given
543+ name).
544+
545+ It's possible to access and manipulate the ` options ` of the resulting elements:
546+
547+ ``` python
548+ selected_option = my_select.options.selected
549+ my_select.options.remove(0 ) # Remove the first option (in position 0).
550+ my_select.clear()
551+ my_select.options.add(html = " Orange" )
552+ ```
506553
507554Finally, the collection of elements returned by ` find ` and ` children ` is
508555iterable, indexable and sliceable:
@@ -512,11 +559,12 @@ for child in my_element.children[10:]:
512559 print (child.html)
513560```
514561
515- Furthermore, three attributes related to all elements contained in the
562+ Furthermore, four attributes related to all elements contained in the
516563collection can be read (as a list) or set (applied to all contained elements):
517564
565+ * ` classes ` - the list of classes associated with the elements.
566+ * ` innerHTML ` - the innerHTML of each element.
518567* ` style ` - a dictionary like object for interacting with CSS style rules.
519- * ` html ` - the ` innerHTML ` of each element.
520568* ` value ` - the ` value ` attribute associated with each element.
521569
522570### ` pyscript.when `
0 commit comments