2

I made a custom loop that delays 300ms on it's each iteration. But in this loop, the line ul.syle.height = i + 'px'; is throwing a error that TypeError: Cannot set property 'height' of undefined at main.js

But the variable ul is working fine above at the line var ul_scrollHeight = ul.scrollHeight;. Then why it is not working inside 'setTimeout'? Here getNextSibling is another function in my code.

function fun1() {
    var ul = getNextSibling(this);
    var ul_scrollHeight = ul.scrollHeight;

    
    var i = 1;

    function customLoop() {
        setTimeout(function () {
            ul.syle.height = i + 'px'; // Not Working

            if (i <= ul_scrollHeight) {
                customLoop();
            }
        }, 300)
    }

    customLoop();

}

3
  • Please also show the relevant html Commented Jan 12, 2021 at 6:33
  • 4
    is it ul.syle.height or ul.style.height ? You may make typo in style i guess. Commented Jan 12, 2021 at 6:34
  • On a side note, customLoop seems to be infinite, since neither i nor ul_scrollHeight ever change. Commented Jan 12, 2021 at 6:40

1 Answer 1

4

I think you just have a typo on that line:

ul.syle.height = i + 'px';

Because ul.syle is missing a t, so that returns undefined, which did not have a property height. 🙂

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.