Home>
About the cases where () is attached or not in Javascript
When you have onclick attribute in html and in event property on script side
When I wrote oclick, I would like to know why ();
<! DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<p id = "ab">test</p>
<script type = "text/javascript">
function a () {
console.log ("Hellow");
}
let p = document.getElementById ("ab");
p.onclick = a;
</script>
</body>
</html>
<! DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<p onclick = "a ();">test</p>
<script type = "text/javascript">
function a () {
console.log ("Hellow");
}
</script>
</body>
</html>
`` `Enter the language name here
javascript
If i add ();in the event properties, it will fire without permission.
Supplemental information (FW/tool version etc.)chrome latest version
-
Answer # 1
Related articles
- javascript - i'm new to gulp gulp processing is not executed
- javascript - map is not a function error
- javascript - [gas] automatic saving of files attached to emails
- javascript is not displayed on html
- javascript does not run on circleci
- javascript - can not be displayed···
- javascript - [rails] when the page is changed, the page is changed to "2020"
- javascript - tab panel does not work
- javascript addeventlistener does not work well
- javascript - js using onclick does not work
- javascript - tab contents are not hidden
- javascript - addeventlistener does not work
- javascript - z-index does not work in full screen menu
- i do not understand the idea of this kind of code in javascript
- javascript - why is cleartimeout not working?
- javascript - i am not sure how to use the array of dataset
- javascript - hamburger menu does not apply
- javascript - jquery does not load
- javascript - not defined error
- javascript - slick does not apply
Trends
p.onclick = a ();
In this process, the return value obtained by executing the function
a
is assigned top.onclick
It is
p.onclick = a
because you must assign the function you want to call when you click.test
Since
onclick = "// JavaScript is described"
in HTML description,a ();