question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot read property 'top' of undefined

See original GitHub issue

Using the latest version of the datepicker I’m getting this error. Following my code:

<div class="control-group">
    <label class="control-label" for="question-15">Start Date:</label>  
    <div class="controls">
        <input type="text" name="start_date[response]" value="" id="question-15" class="required date">
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="question-16">End Date:</label>    
    <div class="controls">
        <input type="text" name="end_date[response]" value="" id="question-16" class="required date">
    </div>
</div>
<script>
$(function(){
    $('.date').datepicker();
});
</script>

When I attempt to do this, I’m getting the following error: Uncaught TypeError: Cannot read property ‘top’ of undefined in bootstrap-datepicker.js on line 148

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
eastsidecommented, Jun 11, 2013

The documentation doesn’t specify this very well, but if you get this error, this is what you’re doing wrong: You have an element with a ‘date’ class, but that element doesn’t contain an element with contains an ‘add-on’ class.

If you have a single input element that you want to be a date field all on it’s own, it should NOT have the ‘date’ class, but SHOULD have the attribute data-date-format. For example, the following markup is correct:

<input type="text" class="span2" value="02/16/12" data-date-format="mm/dd/yy" id="dp2" />

The following markup is incorrect:

<input type="text" class="span2 date" value="02/16/12" data-date-format="mm/dd/yy" id="dp2" />

If you have a div with the ‘date’ class, then it needs a contained element that has the ‘add-on’ class. For example:

<div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  <input class="span2" size="16" type="text" value="12-02-2012" readonly="" />
  <span class="add-on"><i class="icon-calendar"></i></span>
</div>

In other words, when you get this error, it’s basically saying “Hey the ‘date’ class means that you want to use this calendar icon thing, but I can’t find the class with the ‘add-on’! Fix it!” But of course the error message isn’t very helpful and could be improved.

I tried to explain in my comment on February 27, 2013, but I realize how that my explanation was pretty terrible.

0reactions
GabrieleMartinicommented, Jul 30, 2019

Same issue for jQuery v1.10.1 , and same solution: using class different than ‘date’ make it working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'top' of undefined
This malfunction occurs because your href is set to # inside of your <a> tag. Basically, your app is trying to find href...
Read more >
TypeError: Cannot read property 'top' of Undefined in JS
The "Cannot read property 'top' of undefined" error occurs when trying to access the top property on an undefined value. To solve the...
Read more >
Uncaught TypeError: Cannot read property 'top' of undefined
'Undefined' is the property of the global object. This error occurs in Chrome Browser when you read a property or call a method...
Read more >
Uncaught TypeError: Cannot read property 'top' of undefined
I have use one page scroll but not working in live. custom.js:73 Uncaught TypeError: Cannot read property 'top' of undefined at HTMLAnchorElement.
Read more >
Uncaught TypeError Cannot read property top of undefined
Here this line of code: var contentNav = $('.content-nav').offset().top; is firing an error: "Uncaught TypeError: Cannot read property 'top' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found