How do you insert HTML before OJS cells run? #6794
-
DescriptionI wrote the following minimal
and this logs that the I'm guessing that Quarto runs the OJS cell before inserting the HTML. Is there a way to control this order of operations? Or is there some other way to "order" the insertion of HTML elements, such that it occurs before OJS cells are run? (In case anyone is curious, I'm trying to do this because I will eventually have a document with a number of canvas elements, and each should be governed by a different OJS cell. I'd also like to have the OJS code at the bottom of the page, there only for reference. So I'm trying to name the canvases by IDs so that the code at the bottom of the document can find the canvases by ID.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @axiomtutor! Try I believe OJS cells first run after the DOM is loaded, but I'm not 100% sure (they are Promises, so they do update naturally when their dependent cells update, but I'm not sure whether they re-run when DOM nodes change. My instinct is "probably not") . But there are a couple of other problems:
Try this!
This OJS chunk is actually two cells: the first is a named cell, |
Beta Was this translation helpful? Give feedback.
Hey @axiomtutor! Try
document.getElementById("canvas")
. That function takes a bare ID name (without the hash symbol), as opposed to a function likequerySelector()
orquerySelectorAll()
that takes a CSS selector (including the hash).I believe OJS cells first run after the DOM is loaded, but I'm not 100% sure (they are Promises, so they do update naturally when their dependent cells update, but I'm not sure whether they re-run when DOM nodes change. My instinct is "probably not") . But there are a couple of other problems:
console.log(x)
last, you s…