My current project involves creating a to-do list using jQuery and centering everything on the page with text-align: center
in the CSS file. However, I am facing an issue with left-aligning newly added list items below the form.
The JavaScript section of my code is provided below (I suspect this is where modifications need to be made), but you can also check out my CodePen for the HTML and CSS files.
$(function() {
$('.button').click(function() {
let toAdd = $('input[name=checkListItem]').val();
// Appends specified element as last child of target element
$('.list').append('<div class="item">' + toAdd + '</div>');
// Clears input box after clicking 'add'
$('input[name=checkListItem]').val('');
});
$('input[name=checkListItem]').keypress(function(e) {
if (e.which == 13) {
$('.button').click();
// e.preventDefault() prevents default event from occurring, e.stopPropagation() prevents event from bubbling up, and return false does both
return false;
}
});
$(document).on('click', '.item', function() {
$(this).remove();
});
});