This article demonstrates how to access the DOM in WebAssembly from a C program:
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
unsigned int EMSCRIPTEN_KEEPALIVE IncrementClickCountOnValue()
{
// Static variable that hold how many times this function was clicked
static int clicks=0;
// Modify the DOM, through a Javascript call provided by EM_ASM_, getElementById is the DOM API used
EM_ASM_( {document.getElementById("run").value='Webassembly click count: '+$0}, ++clicks );
return 1;
}
If you compile (emcc dom.c -O1 -s MODULARIZE=1 -s WASM=1 -o dom.js) and run it (emrun --no_browser --port 8080 .), it works as expected.
How can I do the same without C, i. e. what would be the equivalent of EM_ASM_( {document.getElementById("run").value='Webassembly click count: '+$0}, ++clicks ); in the WebAssembly text format?