pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Implement document.queryselectorall()

Open LorVC opened this issue 3 years ago • 1 comments

Checklist

  • [X] I added a descriptive title
  • [X] I searched for other feature requests and couldn't find a duplicate (including also the type-feature tag)
  • [X] I confirmed that it's not related to another project area (see the above section)

What is the idea?

If is needed to add a class to multiple elements or do something to multiple things,is needed the use of js Like this for e in document.querySelectorAll("#main > *"): e.classList.add("load") `

Why is this needed

Isn't a pure python library call

What should happen?

Return a list of elements Maybe using a static method

Additional Context

No response

LorVC avatar Aug 09 '22 17:08 LorVC

Done something here #702

LorVC avatar Aug 20 '22 07:08 LorVC

All of the js global objects are exposed in the js module within Pyodide.

Here is an example that loops over results from document.querySelectorAll("#main > *")

example:

<html>
<head>
    <link rel="stylesheet" href="https://pyscript.net/unstable/pyscript.css" />
    <script defer src="https://pyscript.net/unstable/pyscript.js"></script>
</head>
<body>
    <div id="main">
        <div>ch0</div>
        <div>ch1</div>
        <div>ch2</div>
        <div>ch3</div>
        <div>ch4</div>
    </div>
    <py-script>
import js
elements = js.document.querySelectorAll("#main > *")

for element in elements:
    print(element)
    </py-script>
</body>
</html>

tedpatrick avatar Sep 25 '22 23:09 tedpatrick

@tedpatrick should we close this then? https://github.com/pyscript/pyscript/pull/702 Seems like your solution is all-encompassing.

marimeireles avatar Sep 26 '22 12:09 marimeireles