1
I’m getting the following error on the console:
Uncaught Typeerror: Cannot read Property 'top' of Undefined
He is saying that the error occurs on the following line:
alturaproximo = $(this).next().offset().top;
Follows the code:
$('.lego').each(function() {
var alturadesse = $(this).offset().top,
alturaproximo = $(this).next().offset().top;
console.log(alturadesse);
var zindex = 5;
if ( alturadesse == alturaproximo ) {
$(this).css({'z-index': zindex});
} if ( alturadesse > alturaproximo ) {
zindex + 1;
$(this).css({'z-index': zindex});
}
});
I believe he’s not getting the height offset().top
because of the next()
.
Would anyone know what I need to do to compare the distances from the top of an element and the next element equal to it?
It’s not at the end when you get to the last and there’s no next?
– Jader A. Wagner
Man, that was it!! Hahaha. Thank you so much!
– Cauê