Rectangle 27 11

scrollToAnchor('#philosophy-page');
scrollToAnchor('philosophy-page');

Remember you use the name to find the a element:

var aTag = $("div[name='"+ aid +"']");
#philosophy-page

Yep this worked! Thank you!!!! I will mark as right answer... You can accept an answer in 11 minutes StackOverflow says currently

jquery - Cannot read property 'top' of undefined - Stack Overflow

jquery scroll
Rectangle 27 3

var divPos = $(theID).offset().top;
var divPosid = $(theID);
    if (!divPosid.length) {
        return;
    }
    var divPos = divPosid.offset().top; // get the offset of the div from the top of page

jquery - Uncaught TypeError: Cannot read property 'top' of undefined -...

jquery
Rectangle 27 3

var divPos = $(theID).offset().top;
var divPosid = $(theID);
    if (!divPosid.length) {
        return;
    }
    var divPos = divPosid.offset().top; // get the offset of the div from the top of page

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

jquery - Uncaught TypeError: Cannot read property 'top' of undefined -...

jquery
Rectangle 27 4

The issue is because you are attempting to get the offset() of an element which does not exist in the DOM, therefore null is being returned. You are then trying to retrieve a property from the null value which causes an error.

Instead, when assigining the value to top, you need to check that position is assigned correctly. Try this:

var top = position ? position.top : 0;

Note that this will set top to the value of position.top if available, otherwise it will be set to 0.

javascript - Uncaught TypeError: Cannot read property 'top' of undefin...

javascript jquery
Rectangle 27 43

A common cause for Cannot read property 'fnSetData' of undefined is the mismatched number of columns, like in this erroneous code:

<thead>                 <!-- thead required -->
    <tr>                <!-- tr required -->
        <th>Rep</th>    <!-- td instead of th will also work -->
        <th>Titel</th>
                        <!-- th missing here -->
    </tr>
</thead>
<tbody>
    <tr>
        <td>Rep</td>
        <td>Titel</td>
        <td>Missing corresponding th</td>
    </tr>
</tbody>

While the following code with one <th> per <td> (number of columns must match) works:

The error also appears when using a well-formed thead with a colspan but without a second row.

For a table with 7 colums, the following does not work and we see "Cannot read property 'mData' of undefined" in the javascript console:

<thead>
    <tr>
        <th>Rep</th>
        <th>Titel</th>
        <th colspan="5">Download</th>
    </tr>
</thead>
<thead>
    <tr>
        <th rowspan="2">Rep</th>
        <th rowspan="2">Titel</th>
        <th colspan="5">Download</th>
    </tr>
    <tr>
        <th>pdf</th>
        <th>nwc</th>
        <th>nwctxt</th>
        <th>mid</th>
        <th>xml</th>
    </tr>
</thead>

Found your answer useful. My markup was missing the tr used to enclose all th elements. Just leaving it here in case somebody finds this useful!

th
thead

jquery - Datatables: Cannot read property 'mData' of undefined - Stack...

jquery console datatables
Rectangle 27 1

Pass id without # as name does not # in it.

scrollToAnchor('#philosophy-page');
scrollToAnchor('philosophy-page');

jquery - Cannot read property 'top' of undefined - Stack Overflow

jquery scroll
Rectangle 27 1

$(function() {
  $('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});

jquery - Cannot read property 'top' of undefined - Stack Overflow

jquery scroll
Rectangle 27 1

I have made a test case here:

$("a").tooltip();

It looks like there is just an issue with the jquery tools tooltip plugin, it doesn't let you bind to the document object. Try just using the generic "a" tag to bind to and it should work. There are still some styling errors, but it should fix the immediate problem.

I'm afraid Alexander beat you to it, I've downloaded a customer set of tools without the tooltip functions (as I'm using the jQuery UI library for tooltips) and the error is now gone.

javascript - Cannot read property 'top' of undefined - jQuery - Stack ...

javascript jquery html css html5
Rectangle 27 2

You need to test whether the selector matched anything.

function resize() {
    var position= $('.div1').offset();
    if (position) {
        var top= position.top;
        var newtop = top + 60 + "px";
        $('.div2').css( {
            'top': newtop 
        });
    }
}

javascript - Uncaught TypeError: Cannot read property 'top' of undefin...

javascript jquery
Rectangle 27 1

I have made a test case here:

$("a").tooltip();

It looks like there is just an issue with the jquery tools tooltip plugin, it doesn't let you bind to the document object. Try just using the generic "a" tag to bind to and it should work. There are still some styling errors, but it should fix the immediate problem.

I'm afraid Alexander beat you to it, I've downloaded a customer set of tools without the tooltip functions (as I'm using the jQuery UI library for tooltips) and the error is now gone.

javascript - Cannot read property 'top' of undefined - jQuery - Stack ...

javascript jquery html css html5
Rectangle 27 1

I have made a test case here:

$("a").tooltip();

It looks like there is just an issue with the jquery tools tooltip plugin, it doesn't let you bind to the document object. Try just using the generic "a" tag to bind to and it should work. There are still some styling errors, but it should fix the immediate problem.

I'm afraid Alexander beat you to it, I've downloaded a customer set of tools without the tooltip functions (as I'm using the jQuery UI library for tooltips) and the error is now gone.

javascript - Cannot read property 'top' of undefined - jQuery - Stack ...

javascript jquery html css html5
Rectangle 27 1

The error means that $(cache).offset() is returning undefined, which in jQuery terms generally means that $(cache) didn't find anything.

From the layout of your script, it seems that you're likely executing this code right away and the element(s) your looking for may not exist yet (since the document is still loading). Try executing it after the document has fully loaded. In jQuery you can accomplish this by wrapping the code in the jQuery function itself, which by default sets it as a handler to the document's ready event:

$(function () {
    var cache = '.faixatrabalho';
    console.log( cache );

    //store the initial position of the element
    var vTop = $(cache).offset().top - parseFloat($cache.css('margin-top').replace(/auto/, 0));
});

jquery - Getting the error "Cannot read property 'top' of undefined" -...

jquery
Rectangle 27 1

The error means that $(cache).offset() is returning undefined, which in jQuery terms generally means that $(cache) didn't find anything.

From the layout of your script, it seems that you're likely executing this code right away and the element(s) your looking for may not exist yet (since the document is still loading). Try executing it after the document has fully loaded. In jQuery you can accomplish this by wrapping the code in the jQuery function itself, which by default sets it as a handler to the document's ready event:

$(function () {
    var cache = '.faixatrabalho';
    console.log( cache );

    //store the initial position of the element
    var vTop = $(cache).offset().top - parseFloat($cache.css('margin-top').replace(/auto/, 0));
});

jquery - Getting the error "Cannot read property 'top' of undefined" -...

jquery
Rectangle 27 1

The error means that $(cache).offset() is returning undefined, which in jQuery terms generally means that $(cache) didn't find anything.

From the layout of your script, it seems that you're likely executing this code right away and the element(s) your looking for may not exist yet (since the document is still loading). Try executing it after the document has fully loaded. In jQuery you can accomplish this by wrapping the code in the jQuery function itself, which by default sets it as a handler to the document's ready event:

$(function () {
    var cache = '.faixatrabalho';
    console.log( cache );

    //store the initial position of the element
    var vTop = $(cache).offset().top - parseFloat($cache.css('margin-top').replace(/auto/, 0));
});

jquery - Getting the error "Cannot read property 'top' of undefined" -...

jquery
Rectangle 27 15

You need to have data in your table before you can call the sortList method on it. This is because you apply an indexing in this method that will not find any records if there is no data present and that will throw the "Cannot read property '0' of undefined" error.

jQuery TableSorter Plugin error on init : cannot read property '0' of ...

jquery jquery-plugins tablesorter
Rectangle 27 275

FYI dataTables requires a well formed table. It must contain <thead> and <tbody> tags, otherwise it throws this error. Also check to make sure all your rows including header row have the same number of columns.

The following will throw error (no <thead> and <tbody> tags)

The following will also throw an error (unequal number of columns)

<table id="sample-table">
    <thead>
        <tr>
            <th>title-1</th>
            <th>title-2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>data-1</td>
            <td>data-2</td>
            <td>data-3</td>
        </tr>
    </tbody>
</table>

There was extra <td> on my <tbody> when i removed it woked!! thanks a lot

what great solution

Just spent a full day on this issue. The problem? I had 2 th's but 3 td's. Kicking myself at such a silly issue! Thanks so much.

jquery - Datatables: Cannot read property 'mData' of undefined - Stack...

jquery console datatables
Rectangle 27 184

You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

This works Perfect! But I take it this should be used as a patch, rather than a solution right?

Thanks, using a jquery plugin that was using this and this was an easy short term solution until a real fix rolls out.

This answer is no longer correct, since IE11 does not have the MSIE token in the userAgent string.

javascript - Uncaught TypeError: Cannot read property 'msie' of undefi...

javascript jquery jquery-tools
Rectangle 27 183

You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

This works Perfect! But I take it this should be used as a patch, rather than a solution right?

Thanks, using a jquery plugin that was using this and this was an easy short term solution until a real fix rolls out.

This answer is no longer correct, since IE11 does not have the MSIE token in the userAgent string.

javascript - Uncaught TypeError: Cannot read property 'msie' of undefi...

javascript jquery jquery-tools
Rectangle 27 183

You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

This works Perfect! But I take it this should be used as a patch, rather than a solution right?

Thanks, using a jquery plugin that was using this and this was an easy short term solution until a real fix rolls out.

This answer is no longer correct, since IE11 does not have the MSIE token in the userAgent string.

javascript - Uncaught TypeError: Cannot read property 'msie' of undefi...

javascript jquery jquery-tools
Rectangle 27 183

You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

This works Perfect! But I take it this should be used as a patch, rather than a solution right?

Thanks, using a jquery plugin that was using this and this was an easy short term solution until a real fix rolls out.

This answer is no longer correct, since IE11 does not have the MSIE token in the userAgent string.

javascript - Uncaught TypeError: Cannot read property 'msie' of undefi...

javascript jquery jquery-tools