I have an array of items that I want to change the css
in scroll
of my Document, when I give console.log()
, the items are there, but in the loop to change their style, it gives me the message:
Uncaught TypeError: itemsmenu [i] .css is not a function
Event call 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");
}
}
}