'How to access document and element variable when using javscript kernel
When using the python3 kernel the following code works:
%%js
let b = document.createElement("b")
b.textContent="Hi there!"
element.append("A test:")
element.append(b)
and correctly outputs
A test:Hi there!
with Hi there! being bold.
However, when I switch to the javascript kernel and run the above code (without %%js) I get:
evalmachine.<anonymous>:1
let b = document.createElement("b")
^
ReferenceError: document is not defined
at evalmachine.<anonymous>:1:9
at Script.runInThisContext (node:vm:129:12)
at Object.runInThisContext (node:vm:305:38)
at run ([eval]:1020:15)
at onRunRequest ([eval]:864:18)
at onMessage ([eval]:828:13)
at process.emit (node:events:527:28)
at emit (node:internal/child_process:936:14)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
How can I successfully run the code snipped when using the js kernel?
Solution 1:[1]
It is not possible to access those elements. However, it is possible to achieve the same effect using $$.html
$$.html('A test:<b>Hi there!</b>')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sim |
