JavaScript: Update your shopping list activity to use jQuery instead of (JS) standard document object methods. Your implementation should use jQuery to select, add, remove elements, and react to events instead of DOM methods like getElementById, appendChild, addEventListener, etc. Below the JS HTML and JS Shopping List HTML: Shopping List Shopping List Shopping List JS: function addItem(event) { var list = document.getElementById('shoppingList'); var item = document.createElement('li'); var input = document.createElement('input'); var deleteButton = document.createElement('input'); deleteButton.setAttribute('type', 'button'); deleteButton.setAttribute('value','X'); deleteButton.setAttribute('class', 'deleteButton'); deleteButton.addEventListener('click', removeItem, false); input.setAttribute('type', 'text'); input.setAttribute('placeholder', 'List item'); item.appendChild(input); item.appendChild(deleteButton); list.appendChild(item); }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JavaScript: Update your shopping list activity to use jQuery instead of (JS) standard document object methods. Your implementation should use jQuery to select, add, remove elements, and react to events instead of DOM methods like getElementById, appendChild, addEventListener, etc.

Below the JS HTML and JS

Shopping List HTML:

<html>
<head>
<title>Shopping List</title>
</head>

<style>
body {
background-color: #f9f9f9;
font-family: arial;
}
li {
list-style: none;
padding: 5px;
}
.addButton {
padding: 5px 10px;
background-color: #8214c1;
border: none;
border-radius: 3px;
color: white;
font-size: 1em;
}
.deleteButton {
background-color: #f9f9f9;
color: #8214c1;
font-size: 1em;
border: none;
}
input[type=text] {
border: none;
border-bottom: 1px solid grey;
background-color: #f9f9f9;
font-size: 1.2em;
}
input[type=text]:focus {
outline: none;
}

</style>
<body>
<h1>Shopping List</h1>

<ul id='shoppingList'>
</ul>

<input type="button" class="addButton" onclick="addItem()" value="Add Item">

<script type='text/javascript' src='events-activity-answer.js'></script>
</body>
</html>

Shopping List JS:

function addItem(event) {
var list = document.getElementById('shoppingList');
var item = document.createElement('li');
var input = document.createElement('input');
var deleteButton = document.createElement('input');
deleteButton.setAttribute('type', 'button');
deleteButton.setAttribute('value','X');
deleteButton.setAttribute('class', 'deleteButton');
deleteButton.addEventListener('click', removeItem, false);
input.setAttribute('type', 'text');
input.setAttribute('placeholder', 'List item');

item.appendChild(input);
item.appendChild(deleteButton);
list.appendChild(item);
}

function removeItem(event) {
var listItem = event.target.parentNode;
var list = listItem.parentNode;
list.removeChild(listItem);
}

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Fundamentals of JavaScript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education