- Example 1: This example simply put the argument which is string in the onClick attribute of the button which calls a function with a string as an argument using onClick() method.
How do I get script variables in HTML?
If you want to change the text inside another paragraph, then first give the paragraph an id, then set a variable to it using getElementById([id]) to access it ([id] means the id you gave the paragraph). Next, use the innerHTML built-in variable with whatever your variable was called and a ‘.
- 2 | Add some test code to the file. In your new file my-project. …
- 3 | Add the file to your web page. In your index. …
- 4 | Save your files. …
- 5 | Open the web page in Google Chrome. …
- 6 | Open the Developer Console.
You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.