new to Wix and JavaScript here. I want to set a H1 element to a JavaScript variable. I have encountered the problem that Wix doesn’t allow direct access to DOM, as stated in different Stack Overflow questions. I am specifically trying to do document.getElementById
but that isn’t allowed, instead I have to use Wix’s own namespace. I am encountering the problem on this line: $w("#text").text = chosenwebsite;
. Here is my full code:
// Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction
/* global document */
$w.onReady(function () {
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
const websites = ["Internet Archive", "number 2 ", "number 3"];
const chosenwebsite = websites[(getRandomInt(3))];
$w("#text").text = chosenwebsite;
console.log(chosenwebsite);
});
And here is the code on the H1 element: <h1 id="text">websites</h1>
(that’s it, nothing else). And yes, I have set the element id to “text” within the actual Wix editor. This is the error message I keep getting: “Property ‘text’ does not exist on type ‘HtmlComponent'”. I have tried swapping out “text” for “html” but that didn’t help
Thank you.