Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch jQuery examples with vanilla JS? #4

Open
LauraWebdev opened this issue Sep 10, 2021 · 0 comments
Open

switch jQuery examples with vanilla JS? #4

LauraWebdev opened this issue Sep 10, 2021 · 0 comments

Comments

@LauraWebdev
Copy link

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}" />`);
        });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant