Uncaught TypeError: Cannot read property * of undefined



  • Hello everyone:]

    I try to use the next js to add some classes for buttons in the addressfield:

    function stylizeAddressfieldButtons(fieldname)
    {
    	var buttons = document.querySelectorAll('.' + fieldname + ' button.button-addressfield');
    	buttons[0].classList.add("left-button-addressfield"); // * this line
    	buttons[buttons.length - 1].classList.add("right-button-addressfield");
    }
    stylizeAddressfieldButtons('addressfield');
    stylizeAddressfieldButtons('searchfield');
    

    But it doesn't works and shows the error Uncaught TypeError: Cannot read property 'classList' of undefined with a refer to the marked line. But if I try this code in the console, it works without any errors. Somehow buttons are empty to the start of the script, and I think, there must be some event to run the script only after browser load, but I don't know which. I tried DOMContentLoaded, window.onload and body onload="function()", but it doesn't works. I tried to put my script connection to the end of the body and to the end of the head in browser.html, and it still doesn't works.

    Does anyone know how to fix it?


Log in to reply
 

Looks like your connection to Vivaldi Forum was lost, please wait while we try to reconnect.