Javascript in SharePoint Online not working

I use the Modern Script Web Part to inject JavaScript into my site. I want to modify div elements by className with JavaScript. The script is running on my local PC but when I try to run it in SharePoint it doesn’t work.

I want to disappear all div where a “#” is inside. But in SharePoint I don’t get any element. But I can see the div elements in the source code of the page.

<script language="JavaScript">
window.onload = function() {
var myElements = document.getElementsByClassName('pnpRefinersTemplatePersona_9c35c9d6 pnp-persona');
for(var i=0; i<myElements.length; i++){
    if (myElements(i).innerHTML.indexOf("#")!==-1) {
    document.getElementsByClassName('pnpRefinersTemplatePersona_9c35c9d6 pnp-persona')(i).style.display='none';