I am running the following but I get
(index):58 Uncaught TypeError: jQuery.last is not a function
var myId;
jQuery.getJSON("https://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eilimit=500&eititle=Template:Infobox&callback=?", {
disablelimitreport: true,
format: "json"
}, function(data) {
jQuery.each(data.query.embeddedin, function(i, item) {
var $this = $(this);
if($this[0] === jQuery.last()[0]) {
var myId = item.pageid;
}
console.log(myId);
});
});
JsFidlle see console
Just get the length of the element and move the index back.. Try this one. Hope will work in you.
var myId;
jQuery.getJSON("https://en.wikipedia.org/w/api.php?
action=query&list=embeddedin&eilimit=500&eititle=Template:Infobox&callback=?", {
disablelimitreport: true,
format: "json"
}, function(data) {
jQuery.each(data.query.embeddedin, function(index, item) {
var length = data.query.embeddedin.length;
if (index === (length - 1)) {
var myId = item.pageid;
console.log('The last pageid is : ' + myId);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With