Solution 1 :

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.

Problem :

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();

}

Comments

Comment posted by Maheer Ali

Please also show the relevant html

Comment posted by Robin

is it

Comment posted by VLAZ

On a side note,

By