Waypoints – jQuery.Deferred exception: Cannot read property - javascript

I'm getting a bunch of errors when using Waypoints. Everything is behaving as it should, except enableAll(), despite disableAll() working as it should. The main errors are:
jQuery.Deferred exception: Cannot read property 'top' of undefined TypeError: Cannot read property 'top' of undefined
Uncaught TypeError: Cannot read property 'top' of undefined
I am building my Waypoints from an array, which is what I think is causing the problem. The array contains IDs which I am then adding a string to to create a corresponding Waypoint:
var links = ['#id1', '#id2', '#id3', '#id4'];
$(document).ready(function () {
$.each(links, function (p, linkP) {
var inview = new Waypoint.Inview({
element: $(linkP + 'Content'),
...

Related

Chrome Console Script broken: Uncaught TypeError: Cannot read properties of undefined (reading 'push')

I'm using the following code on Instagram follow request page to open each user in a new tab and then unfollow it.
https://www.instagram.com/accounts/access_tool/current_follow_requests
var i=0;
var unfollow="global";
var final="global";
var link=["link","link2"];
var proWindow=[""]
proWindow.length=0
link.length=0;
var ids = document.querySelectorAll(".-utLf");
for(i=0;i<ids.length;i++){
link.push('https://www.instagram.com/'+ids[i].innerText+'/');
console.log(link[i]);
proWindow[i]=window.open(link[i]);
}
and then the following code to unfollow each user:
for(i=0;i<ids.length;i++){
unfollow = proWindow[i].document.querySelector("button.sqdOP");
unfollow.click();
await new Promise(resolve => setTimeout(resolve, 1000));
final = proWindow[i].document.querySelector(".aOOlW");
final.click();}
console.log("Completed");
however, I'm seeing the following error on the console
Uncaught TypeError: Cannot read properties of undefined (reading 'push')
This preivously used to work fine but now is showing this error.
What change needs to be done to fix this code?
This error originates from trying to push something undefined to an array.
That could happend if the nodelist returned by the queryselector contains something with an undefined innertext for some reason.
This should work better:
if (ids[i].innerText){ // To check if the value is undefined
link.push('https://www.instagram.com/'+ids[i].innerText+'/');
console.log(link[i]);
proWindow[i]=window.open(link[i]);
}

Draggable/Sortable nesting issue (error in onDragStart)

I'd like to both drag the row of items as well as the items itself, within the same or across different rows. It works until I try to move the last item of a row which then results in an error.
jsfiddle:
https://jsfiddle.net/lexixon/nf97erqx/64/
Error:
Uncaught TypeError: Cannot read property 'element' of null
at VueComponent.onDragStart (vuedraggable.js:380)
at mt.<anonymous> (vuedraggable.js:37)
at Ct (Sortable.min.js:3)
at mt._dragStarted (Sortable.min.js:3)
Uncaught TypeError: Cannot read property 'index' of null
at VueComponent.onDragRemove (vuedraggable.js:403)
at mt.<anonymous> (vuedraggable.js:37)
at Ct (Sortable.min.js:3)
at mt._onDrop (Sortable.min.js:3)
at mt.handleEvent (Sortable.min.js:3)

TypeError: null is not an object (evaluating '*')

For the below code:
var item = cartModel.getlist()[index];
if((item.isDepo()) {
// Some code
} else if(!permission.hasPermissionToVoidSKU()) {
// Some code
} else if(item.sku.indexOf(mposConstants.RESTOCK_FEE_SKU) > -1){
// Some code
}
I'm getting this error:
TypeError: null is not an object (evaluating 'item.sku.indexOf')
If item object is null, the error is something different (see below). In what scenario will this error be thrown?
Update:
If item.sku is null, the error is:
[FATAL] [] [-] ["TypeError: Cannot read property 'indexOf' of null
If item is null, the error is:
[FATAL] [] [-] ["TypeError: Cannot read property 'isDepo' of null
The reason for the different error messages is quite simply that they are produced by different browsers. The error is the same (sku on the object item is null).
Given the following code
<script>
var item = {sku: null};
item.sku.indexOf("");
</script>
here is some error messages for different browsers:
Firefox: TypeError: item.sku is null
Firefox Developer Edition: TypeError: item.sku is null, can't access property "indexOf" of it
Opera: TypeError: Cannot read property 'indexOf' of null
at example.html:3
Safari: TypeError: null is not an object (evaluating 'item.sku.indexOf')
To get the error message you have gotten, item must be defined as an object, and sku must be set to null. If sku were undefined, you would have gotten an error message like this (Safari): TypeError: undefined is not an object (evaluating 'item.sku.indexOf'). If item was null, you would have gotten something like this: TypeError: null is not an object (evaluating 'item.sku').
Based on this answer and others, it sounds like you're getting that error because a function is called before the DOM element it references or acts upon has been loaded.
In the snippet of code you provided, I don't see a direct reference to any DOM elements, but I would suggest calling your script after your HTML has finished rendering (i.e. by putting any <script> tags at the end of your HTML, or by using a $(document).ready() call if you use jQuery).

adding a custom jquery.validation method results in Uncaught TypeError: Cannot read property 'call' of undefined

I am battling to get jquery.validation to work with a custom method.
I am trying this
$.validator.addMethod("validateMe", function (value, element) {
alert("validate");
});
$( "#myTextBox" ).rules( "add", {
validateMe: true
});
I am using jquery.validate v1.12 but when trying to validate I get an error of
Uncaught TypeError: Cannot read property 'call' of undefined
Am I missing something here?
If anyone else has the same problem it turns out I wasnt providing a message
$.validator.addMethod("validateMe", function (value, element) {
alert("validate");
}, 'Hello message!');
did the trick

console error when using jquery - Uncaught TypeError: Object #<HTMLElement> has no method

I'm trying to add a class or a css style using the following js but getting a console error
var i = 0;
$(".question")[i].addClass("show");
get the following console log error: Uncaught TypeError: Object # has no method 'addClass'
or / and
$(".question")[i].css("display", "block");
get the following console log error: Uncaught TypeError: Object # has no method 'css'
used info from http://api.jquery.com/get/
EDIT
Still doesn't working if get rid of the variable i, and use numbers 0 or 1
When you access an item from a collection with a subscript like [i], you're actually unwrapping it from the jQuery object, and accessing a raw DOM node, which doesn't have methods like addClass and css.
Use .eq() instead:
var i = 0;
$(".question").eq(i).addClass("show");
$(".question").eq(i).css("display", "block");

Categories