I couldn't find it on the docs properly, so can you guide in which case to use what in pyscript ?
I couldn't find it on the docs properly, so can you guide in which case to use what in pyscript ?
You can use either. I prefer to use getElementById() and other native JavaScript functions as that provides an improved interface to the browser DOM.
getElementById() is a native function. That means there is well-written documentation on how to use the API and numerous articles on the Internet. Also, the entire JavaScript namespace (functions and variables) is imported into Python. By sticking with one namespace you are not switching back and forth between PyScript features that are wrappers for native features and just using native features.
IMHO the PyScript team is trying to develop an API just for PyScript. That is not hard to do, but I feel that API is not necessary and will hinder PyScript adoption. The JavaScript API works effortlessly in Python due to the bindings that the Pyodide team created. Pyodide is the engine that PyScript uses. 99% of the time, you do not even need the PyScript wrapper, you can directly run Python via Pyodide. I wrote an article on how to run Python code in the browser. The last section of my article shows how to create your own tags for Python. link If you are just getting started with PyScript review this link.
A JavaScript developer would not know what Element() does but will know what getElementById() does. The decision is up to you on which to use. I recommend learning both APIs and practicing with both. That way you can develop using everything available.