Skip to content

Instantly share code, notes, and snippets.

@alexdev27
Created February 5, 2017 19:53
Show Gist options
  • Save alexdev27/1018d593172aded943f2b5d867881349 to your computer and use it in GitHub Desktop.
Save alexdev27/1018d593172aded943f2b5d867881349 to your computer and use it in GitHub Desktop.
установка активного элемента в зависимости от url
$(function() {
$('.aside-nav__item, .mob-menu__list li').each(function(indx) {//поиск нужных элементов
var e = $(this);
e.removeClass('aside-nav__item--active active-item');
var href = location.pathname.split("/")[1] ;
if (href === '') {
e.find('a[href^="index.html"]') .parent(e)
.addClass('aside-nav__item--active');
}
else{
e.find('a[href^="' + href + '"]')
.parent(e).addClass('aside-nav__item--active');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment