A minimal, jQuery-compatible helper library for modern JavaScript projects
$(() => {
$('.btn').on('click', () => {
$('.btn').toggleClass('highlight');
});
});
$('#changeText').on('click', () => {
$('#textOutput').text('Text updated using .text()');
});
$('#showName').on('click', () => {
const name = $('#nameInput').val();
$('#nameResult').text('Hello, ' + name + '!');
});
$('#changeStuff').on('click', () => {
$('#myLink').attr('href', 'https://myappz.com').text('Visit MyAppz');
const checked = $('#myCheck').prop('checked');
$('#box').css('backgroundColor', checked ? '#28a745' : '#f8d7da');
});
$('#loadData').on('click', () => {
$.ajax({
url: 'https://jsonplaceholder.typicode.com/todos/1',
success: data => {
$('#output').text(JSON.stringify(data, null, 2));
}
});
});
let counter = 3;
// Delegated click handler for .item buttons inside #list
$('#list').on('click', '.item', function (e) {
alert(`Clicked: ${this.textContent}`);
});
// Dynamically add a new item
$('#add').on('click', function () {
const newBtn = document.createElement('button');
newBtn.className = 'item';
newBtn.textContent = `Item ${counter++}`;
$('#list')[0].appendChild(newBtn);
});