简体   繁体   中英

How do I fix Cannot read property 'style' of null in JavaScript?

So my function Updates the progress bar based on the document.load set value. From What I can see, its not able to render that element. After extensive research I am not sure why my other divs can be recognised and manipulated in JS but not this specific element;

<div id="ProgressBar">
     <div id="Percentage" class="innerBar" runat="server"></div>
</div> 

<script type="text/javascript">

    $(document).ready(function () {
        SpaceLeftVar = 32;
        UpdateProgress();
    });

function UpdateProgress() {

    const progressBarPercentage = document.getElementById('Percentage');

    const transitionProgressBar = (progress) => {

        setTimeout(() => {
            progressBarPercentage.style.width = progress + '%';
         }, 200);
    }
}
</script>
setTimeout(() => { 
    progressBarPercentage && (progressBarPercentage.style.width = progress + '%')
}, 200); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM