As someone new to javascript, I'm eager to create a code that will consistently search for a specific div class in an HTML file and then assign another class to my navigation if the required class is found. Although I attempted to write the code myself, unfortunately it doesn't seem to be functioning as intended.
function myFunction(e) {
var element = document.getElementById('nav-verslui');
var div = document.querySelector('div');
if (div.classList.contains('privatiemsverslui-verslui999')) {
element.classList.add('active-verslui');
} else {
element.classList.remove('active-verslui');
}
};