Skip to content

How to define functions in script block? #16

Answered by ZuperZee
sensor-freak asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @sensor-freak.

You can't define functions in the html document, but you are able to add functions in onInit and onRender.

There are some examples at https://github.com/gapitio/gapit-htmlgraphics-panel/tree/main/examples/simple-example on how to add click events and such.

The easiest way to add what you're doing is to set the event in onInit instead of the html document.

const overlayElt =  htmlNode.getElementById("overlay");
const boxElt =  htmlNode.getElementById("BH7 1");

function showOverlay() {
  // htmlNode instead of document
  overlayElt .style.display = "block";
}
function hideOverlay() {
  overlayElt .style.display = "none";
}

overlayElt.onclick = hideOverlay;
boxElt.onclick

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sensor-freak
Comment options

Answer selected by ZuperZee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants