Untitled

mail@pastecode.io avatar
unknown
javascript
9 days ago
1.1 kB
5
Indexable
Never
// Dodavanje zadatka s kategorijom
$('#add-task-btn').on('click', function() {
    let taskText = $('#new-task').val();
    let selectedCategory = $('#category-select').val();
    if (taskText === "") return;

    let taskItem = $('<li></li>');
    taskItem.html(`<span class="category">[${selectedCategory}]</span> <input type="checkbox"> ${taskText} <button class="delete-btn">Obriši</button>`);
    $('#task-list').append(taskItem);
    $('#new-task').val('');

    // Označavanje završenih zadataka
    taskItem.find('input[type="checkbox"]').on('change', function() {
        taskItem.toggleClass('completed');
    });

    // Brisanje zadatka
    taskItem.find('.delete-btn').on('click', function() {
        taskItem.remove();
    });
});

// Filtriranje po kategoriji
$('#filter-category-btn').on('click', function() {
    let filterCategory = $('#category-select').val();
    $('#task-list li').each(function() {
        if ($(this).find('.category').text() !== `[${filterCategory}]`) {
            $(this).hide();
        } else {
            $(this).show();
        }
    });
});
Leave a Comment