If the property name of the Javascript is '-', the code cannot be executed properly.

Asked 2 years ago, Updated 2 years ago, 365 views

When I tried to execute the following code on the browser console, it was recognized separated by - and the code could not be executed successfully.I'd like to know how to deal with it, but could you tell me how to deal with it?

 document.example-form-name.submit()

javascript html

2022-10-22 09:12

1 Answers

Use bracket notation.

 document ["example-form-name"].submit()

Generally, if the property name is not a valid JavaScript identifier, do this.


2022-10-22 09:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.