Habbo-API icon indicating copy to clipboard operation
Habbo-API copied to clipboard

switch jQuery examples with vanilla JS?

Open LauraWebdev opened this issue 4 years ago • 0 comments

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}" />`);
        });
    });

LauraWebdev avatar Sep 10 '21 16:09 LauraWebdev