2

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') 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?

1 Answer 1

1

I'm not sure why MyForm.element doesn't work. I feel like it should work, but in any case. I found that you can use document.body to get the body tag instead of MyForm.element.

So the code to set a data attribute for the body would be:

document.body.setAttribute('data-test','form');

And that's working fine now.

2
  • I suspect that you try to access the form element while the form is being created. That's probably too early. You might have better luck when trying to access the element at a later time.
    – NineBerry
    Oct 4 at 12:15
  • @NineBerry I just tested it. It's still not working at a later stage. If I do .element for any other component, then it finds the component except for the form. Oct 4 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.