How to get/edit a html tag with pyscript?

How to get/edit a html tag with pyscript?

1 Like

You can grab elements with id using Element

tree = Element("id")

we can grab the child with the class element using select

leaf =".leaf")

There is more you can check out the examples in pyscript repo

Thanks! It works!!~~~~

Is there a way to grab the class attribute of an element and change its value?

The entire JavaScript namepsace is available to PyScript applications.

One easy method is to access the DOM in Python is like this:

from js import document

paragraph = document.getElementById("header")
paragraph.className = "yellow blue"

By using that method you have the full power to do anything JavaScript can do.

1 Like