S
S
Sergey Valitov2015-10-12 21:31:55
JavaScript
Sergey Valitov, 2015-10-12 21:31:55

Why is offset().top throwing an error?

Hello! There is this code:

var elem = jQuery('.table-price-wrapper tr').eq(find);
            var ypos = jQuery(elem).offset().top;
           jQuery('.table-price-wrapper tr').removeClass('active');
        	jQuery('.table-price-wrapper').animate({scrollTop: jQuery('.table-price-wrapper').scrollTop() - 20 + ypos + 'px'}, 700);
            jQuery('.table-price-wrapper tr:eq(' + find + ')').addClass('active');

In the console, the error immediately - Uncaught TypeError: Cannot read property 'top' of undefined
What could be the error? the find variable is a digit that always exists.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-10-13
@serejatoje

Butter oil...

//eq возвращает jQuery-объект, а не обычный элемент
//И получается у вас такое действо:
$($(something)).offset().top;

-->
hmm....check what happens in elem ?

I
Ivanq, 2015-10-12
@Ivanq

Check the find variable, if it is greater than the number of elements, there will be an error like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question