A minimal, jQuery-compatible helper library for modern JavaScript projects
//microQuery - Version
$(() => {
const btns = $('.btn');
btns.on('click', () => {
btns.toggleClass('highlight');
$.ajax({
url: 'https://jsonplaceholder.typicode.com/todos/1',
success: data => {
$('#output').text(JSON.stringify(data, null, 2));
}
});
});
});
//Vanilla JS Version
document.querySelectorAll('.btn').forEach(button => {
button.addEventListener('click', () => {
// Toggle class on all .btn elements
document.querySelectorAll('.btn').forEach(el => {
el.classList.toggle('highlight');
});
// AJAX request using fetch
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
})
.catch(err => {
console.error('Fetch error:', err);
});
});
});
Live Examples