The WordPress theme I'm using adds two logos, a dark one when the site loads, and a lighter one when the sticky nav is activated upon scroll. When the sticky nav is active the class 'scrolled' is added to the containing div, 'scroll_header_top_area'.
The code below works if I've already scrolled down the page and the sticky nav is active and I refresh the page, but it doesn't switch out the logos dynamically when scrolling.
I've seen the suggestions to use MutationObserver but I'm afraid I can't understand the example or how to use it here.
How would I change this code to make the change dynamic based upon whether the 'scrolled' class is active.
if ( $j('.scroll_header_top_area').hasClass('scrolled')) {
$j(".q_logo img").attr("src","path_to_image/light.png");
}
else {
$j(".q_logo img").attr("src","path_to_image/dark.png");
}