Make HTML Event Attributes Work like onclick #1029
Replies: 1 comment 1 reply
-
A regular When you use If you need this, you can explicitly assign the function to the global scope: <button onclick="handleClick()">Click</button>
<script>
window.handleClick = function handleClick() {
alert('Wow! You clicked me.');
}
</script> Alternatively, you can use |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
You cannot use
onclick
or other attributes in a pure.astro
file. You have to manually create event listeners and unsubscribe to them.Background & Motivation
Regular JS doesn't even work as you would expect in a
.astro
file.It requires 2x as much code. Pure HTML doesn't require this.
Goals
A concise, bulleted-list outlining the intended goals of this RFC.
script
tagsastro
VS Code would also need to be updated to reflect thisExample
This is so much more work than adding event listener and removing it. This is how pure html is supposed to work.
J
Beta Was this translation helpful? Give feedback.
All reactions