Hi,
I’m trying to add a class (.active) to a div (.target) on page load when the URL has a specific slug (#active). Is that possible with java script?
Here is my site Read-Only: Webflow - Test Site
Hi,
I’m trying to add a class (.active) to a div (.target) on page load when the URL has a specific slug (#active). Is that possible with java script?
Here is my site Read-Only: Webflow - Test Site
With JS, certainly. Check the URL, find your div, add your class.
Thanks, this seems to work:
<script>
document.addEventListener('DOMContentLoaded', function () {
if (window.location.hash === '#active') {
var targetDiv = document.querySelector('.target');
if (targetDiv) {
targetDiv.classList.add('active');
}
}
});
</script>