This is a simple web application that allows users to create and manage a shopping list. Users can add items to the list and remove them when they're done.
- Add Items: Type an item into the input field and click the "Add Item" button (or press Enter) to add it to the list.
- Remove Items: Click the "x" button next to an item to remove it from the list.
- Clean and Efficient: Uses event delegation for efficient removal of list items.
- User-Friendly: Simple and intuitive interface.
- Enter Key Support: Pressing Enter in the input field adds the item.
- HTML
- CSS
- JavaScript
- Clone the Repository (Optional): If you want to run this locally, you can clone this repository:
git clone [repository URL] - Open the HTML File: Open the
index.htmlfile in your web browser. - Add Items: Type the name of an item in the input field and click the "Add Item" button or press Enter.
- Remove Items: Click the "x" button next to the item you want to remove.
index.html: The main HTML file containing the structure and content of the shopping list app.style(within the<style>tags inindex.html): Contains the CSS styles for the app's appearance.script(within the<script>tags inindex.html): Contains the JavaScript code for the app's functionality.
-
Event Delegation: The JavaScript code uses event delegation to handle the removal of list items. This means that instead of adding an event listener to each individual "x" button, a single event listener is attached to the parent
<ul>element. When a click occurs, the event listener checks if the clicked element has the class "remove-button". If it does, the corresponding list item is removed. This is a more efficient approach, especially when dealing with a large number of items or dynamically added items. -
textContent: The code usestextContentto set the text of the list items.textContentis generally preferred overinnerHTMLbecause it is safer (prevents potential cross-site scripting (XSS) vulnerabilities) and performs better. -
trim(): Thetrim()method is used to remove any leading or trailing whitespace from the input value before adding it to the list. This prevents users from accidentally adding empty list items.
- Local Storage: Implement local storage to save the shopping list so it persists even after the browser is closed.
- More Styling: Improve the styling of the app to make it more visually appealing.
- Edit Functionality: Add the ability to edit existing list items.
- Quantity Input: Allow users to specify the quantity of each item.
- Checkboxes/Mark as Purchased: Add checkboxes or a way to mark items as purchased.
Contributions are welcome! If you have any suggestions or bug fixes, please open an issue or submit a pull request.