Assigning contents of HTML box to a variable

I’m trying to move the contents of an HTML box to a variable. Here is my code…

$w . onReady ( function () {

var myVariable = “” ;
let element = $w ( ‘#html1’ );
myVariable = element . text ;

$w ( “#button1” ). onClick (() => {
console . log ( myVariable );

});
});

When I run the page and click the button, the console shows “undefined” for myVariable.

The html1 box only has one line of text, “Hello cruel world,” which is what I would expect to be passed to myVariable, but I get “undefined” instead.

What am I doing wrong here? Perhaps .text can only be used on text elements, and not an html box? If so, is there some other way to do this?

Thanks