Domanda

Mi sto chiedendo se è possibile aggiungere ad un link, che ha lo stesso href come documento.href?

Ho provato, ma senza fortuna.

if ($("a").attr("href") == document.location.href) {
    $(this).addClass("active");
}
.

non è possibile ??

È stato utile?

Soluzione

$("a").filter(function() {
    return this.href === document.location.href;
}).addClass("active");

Should work.

Altri suggerimenti

$("a[href=" + document.location.href + "]").addClass("active");

(not tested)

Have you tried window.location.href instead of document.location.href?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top