How to register events in JavaScript?
Answers
Here is your answer..
If you add the parenthesis, the JavaScript engine things you are trying to run a function and assign a value to the onclick method.
The following code defines a JavaScript function that changes the background color for the button.
function ChangeColor() {
this.style.backgroundColor = "#000000";
}
When a user clicks the button named myButton, the button's background color is changed to black, which is the color that corresponds with the hexadecimal value "#000000." Most designers need to look up color values when they assign font or background colors, but the two basic ones are black and white ("#FFFFFF"). You'll also notice that we used the "this" definition, which indicates that the button clicked is the one we want to change.
You can also use this type of event registration with multiple HTML elements. Using "this," you can change styles and properties without passing the element's name to the event handler. Take the following code as an example.
myButton.onclick = ChangeColor;
myOtherButton.onclick = ChangeColor;
The above code defines two buttons named "myButton" and "myOtherButton" and assigns the same event handler to the "onclick"button. Using the same function code, the "this" assignment points the function to the currently clicked button. This type of coding makes your code more dynamic and efficient, so you don't need to specify the button that is clicked for each element on your page.
◆◆◆●●●●●●●●●◆◆◆◆◆●●●◆◆◆◆
#Hope it helps
# pleasured to help
#Be brainly...:)