In short, I have a form that is named MyForm. Looking at the compiled HTML in the browser, I can see that the form is equal to the body tag. I can prove this by changing the form's color to blue and then I can clearly see the body tag has the background color of blue set on it.
So here's my Delphi code where I am trying to get the form's element and then setting a data attribute for it:
MyForm.element.setAttribute('data-test','form');
This results in an error:
Uncaught TypeError: Cannot read properties of null (reading 'setAttribute')
So it's not finding the element of the form. I can prove this by simply doing a console.log(MyForm.element) and that returns a null.
Doing this same code on any other component works perfectly fine except on the form.
How can I select the form's element (body tag) using Delphi?

I'm not sure why
MyForm.elementdoesn't work. I feel like it should work, but in any case. I found that you can usedocument.bodyto get the body tag instead ofMyForm.element.So the code to set a data attribute for the body would be:
And that's working fine now.