2
I have an array of items that I want to change the css
in the scroll
of my Document, when I give a console.log()
, the items are there, but in the loop to change their style, give me the message:
Uncaught Typeerror: itensmenu[i]. css is not a Function
Call of the event Scroll
:
$(document).scroll(function(){
var brand = $('#brand');
var posicao = window.pageYOffset;
var navbar = $('#navbar');
var itensmenu = $(".nav-item");
var topo = $("#topo");
trocaNav(navbar, topo, posicao, brand, itensmenu);
});
Loop:
function trocaNav(navbar, topo, posicao, brand, itensmenu){
if (posicao == 0){
navbar.css("background-color", "transparent");
brand.attr("src","img/logo_BP.png");
} else{
navbar.css("background-color", "white");
brand.attr("src","img/logo.png");
}
for(var i = 0; i < itensmenu.length; i++){
if (posicao == 0) {
itensmenu[i].css("background-color", "white");
itensmenu[i].css("color" , "white" );
} else{
itensmenu[i].css("background-color", "black");
itensmenu[i].css("color", "black");
}
}
}
I made some adaptations, the third way worked perfectly.
– Tiago Silveira
@Guilhermenascimento the return is different, but in this case it would also work with certainty http://stackoverflow.com/questions/4709660/jquery-eq-vs-get I already delete the comment
– Miguel
@Guilhermenascimento ok, but you can always put that addition, it would have more visibility
– Miguel
@Guilhermebirth of nothing, rich response
– Miguel