Removing first string character with substr in WordPress

I am trying to remove the "|" from the file size span tag. The syntax of my javascript code so far does look fine, but it’s not working quite yet.

From my understanding I am using the proper syntax for substr: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

In Chrome, I am getting this console error:
Uncaught TypeError: Cannot read property ‘substr’ of undefined

In Firefox, I am getting this console error:
Uncaught TypeError: innerTextString is undefined.

Also the "|" isn’t being removed as intended. Any ideas where I am going wrong here?

Thank you in advance.

HTML

<div class="prettyFileList">
    <div>
        <a href="#" class="prettylink">
            <span class="float_right">| Size 150 KB</span>
            <span class="float_right">28th Jan 2021</span> 
        </a>
    </div>
</div>

CSS

.prettyFileList .float_right {
    float: right;
}

JS (loading underneath the HTML)

<script>
    const prettyLinkRightFileSize = document.querySelectorAll('.prettyFileList .float_right:nth-child(1)');
    const innerTextString = prettyLinkRightFileSize.innerText;
    innerTextString.substr(0);
</script>

30 thoughts on “Removing first string character with substr in WordPress”

Leave a Comment