Answer the question
In order to leave comments, you need to log in
How to change the picture for the current menu item?
Good afternoon!
I have a navigation bar, let's say it looks like this:
<aside>
<div id="menu">
<a href="{% url 'home' %}" class="home">
<img class="home-img" src="{% static 'main/img/home.svg' %}">
<span class="navigation_label">Home</span>
</a><br>
<a href="{% url 'orders' %}" class="orders">
<img class="orders-img" src="{% static 'main/img/orders.svg' %}">
<span class="navigation_label">Orders</span>
</a><br>
<a href="{% url 'account' %}" class="Account">
<img class="account-img" src="{% static 'main/img/account.svg' %}">
<span class="navigation_label">Account</span>
</a><br>
</div>
</aside>
const itemMenu = $('#menu a');
const url = location.pathname;
itemMenu.each(function (el) {
if($(this).attr('href') === url) {
$(this).addClass('current')
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question