Skip to content

Instantly share code, notes, and snippets.

@luisfelipe-dev
Last active November 12, 2018 12:09
Show Gist options
  • Select an option

  • Save luisfelipe-dev/d240e3891b162c4f074a977912cd85c0 to your computer and use it in GitHub Desktop.

Select an option

Save luisfelipe-dev/d240e3891b162c4f074a977912cd85c0 to your computer and use it in GitHub Desktop.
<script>
$(document).ready(function() {
var url = window.location;
var element = $('ul.sidebar-menu a').filter(function() {
return this.href == url || url.href.indexOf(this.href) == 0; }).parent().addClass('active');
if (element.is('li')) {
element.addClass('active').parent().parent('li').addClass('active')
}
});
</script>
----
Melhor Opção:
$(function() {
// this will get the full URL at the address bar
var url = window.location.href;
// passes on every "a" tag
$(".menu .content-menu ul a").each(function() {
// checks if its the same on the address bar
if (url == this.href) {
$(this)
.closest("li")
.addClass("active");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment