Hello,
I tried to run very simple javascript inside HTML macro in Confluence page.
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } |
The button is showed but when I click it, the function didn't work.
Any help?
Thanks,
Daniel
Hi Daniel,
Could you try to change the order like this?
<!DOCTYPE html> <html> <head> </head> <body> <h2>JavaScript in Head</h2> <p id="demo">A Paragraph.</p> <button type="button" id="buttonId" onclick="myFunction()">Try it</button>
<script type="text/javascript"> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; }
</script>
</body> </html>
Regards
Agreed!
The script executed before the component is created. document.getElementById("demo") will be return undefined
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.