0
I have a Nav with 5 buttons, and a footer with the same amount, when clicking on the footer buttons they serve anchor to the page, but I need to compare with the Nav items to add the class "Active in them".
Only you’re returning me
btnnav[i].attr("href")
is not a Function
What to do?
$('footer li a').click(function(){
var hfooter = $(this).attr("href");// Guarda o href desse botao no footer
var btnnav = $(".btn-nav");//cria um array com todos os botoes da nav
btnnav.removeClass("active");//tira a classs active deles
for (var i = 0; i <= btnnav.length; i++) {
if (btnnav[i].attr("href") === hfooter){
/*Ao percorrer o array de classes ele deve buscar o que tem o
href igual o botao que foi clicado, quando encontrar,
vai adicionar a class active*/
btnnav[i].addClass("active");
}
}
});
Try to give a
console.log(btnnav)
and show the result– Jéf Bueno
It takes as if it were an array itself, shows all the Nav items, the problem is when I try to catch the href....
– Tiago Silveira
Which is a array all right, but it has to be an array of jQuery objects. Can you create an executable example in the question? Without an example all possible answers will be kicks.
– Jéf Bueno
Transform into a Jquery object in this way $(btnnav[i]). attr("href")
– Diego Schmidt