Javscript to click button on web Page

AppleScript has not worked that well in my current application and I have turned to using JavaScript with in AppleScript.

tell application "Safari"
	do JavaScript "document.getElementById('main-filter-button').click()"
end tell

I am doing something wrong as this returns missing value. I obtained the Id from the HTML code I scrapped from the web site as follows.

Any ideas about what I am doing incorrectly?

Thanks

button class=“mp-page-filter-all-filter-button mp-page-filter-all-filter-button__on_page 12” data-action=“click->component-render#show click->filter#popupState” data-controller=“filter” data-special-theme=“DEC_DATE_MONTH_BEFORE_NOW” id=“main-filter-button”

I’m no expert, but I was trying to do this recently, got the same result, and assumed that it was a security protection in Safari, since the JavaScript hasn’t come from whoever created the page. Just guessing. Discouraging too.

I finally got this to work, I had left the instruction as to where!

do JavaScript "document.getElementById('main-filter-button').click();" in document 1