Valid selector issue

Hi y’all,

I’m a little rusty with my JS (it’s been about 10 years), but I’ve been following a tutorial to create a animated number counter. https://www.wix.com/corvid/forum/community-discussion/how-to-create-animated-number and stepping through the Corvid Documentation. However, I seem to be running into an issue where I’m getting a valid selector error on the text field. I named the textbox “counter1” and my code is here:

let startNum = 0;
let endNum = 500;
const duration =  1000; // 1000 milliseconds 

$w.onReady(function () {
    setInterval(()=> {
        countUp();  
    }, duration);
});

function countUp(){ 
 if (startNum <= endNum ){
        $w('#counter1').text = startNum.toString();
        startNum++;
    }
}

I’m wondering if I’m missing something obvious or if I’m missing a crucial step? Any help would be great. Thanks in advance!

Matthew, I copied and pasted your code onto a page, added the #counter1 text element, and the text element displayed sequential numbers without errors. It seemed to work as designed.

That’s super interesting. Thanks for trialing it for me. I seem to get the Valid Selector error every time I try it. I’ve even deleted elements, added new, renamed, and tried on different pages and nothing. Very strange.

You might try deleting the text element and then add another one with the same name …