Habbo-API
Habbo-API copied to clipboard
switch jQuery examples with vanilla JS?
I was wondering if using jQuery for the JS examples is still neccessary, since the Fetch API is widely available nowadays.
The effort would be somewhat small, would cover more cases (for example: NodeJS) and not depend on a big (nowadays) unnecessary library that is slowly losing usage.
jQuery:
$(function(){
// Get Badges from our API
$.getJSON('https://api.habboapi.net/badges?per_page=50', function(badges){
$.each(badges.data, function(key, badge){
// Append badges to div
$('#badges').append('<img src="' + badge.image + '" />');
});
});
})
Vanilla JS:
fetch('https://api.habboapi.net/badges?per_page=50')
.then(response => response.json())
.then(badges => {
badges.data.forEach((badge, key) => {
document.body.insertAdjacentHTML('beforeend', `<img src="${badge.image}" />`);
});
});