Tell us what’s happening:
the test says i should use the remove method to remove the parent element of buttonEl. what am i doing wrong??
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const deleteTask = (buttonEl) => {
const dataArrIndex = taskData.findIndex(
(item) => item.id === buttonEl.parentElement.id
);
buttonEl.remove(parentElement);
taskData.splice(dataArrIndex, 1);
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
Learn localStorage by Building a Todo App - Step 44
1 Like
have a look at this mdn article about how ti use “remove()”, happy reading Element: remove() method - Web APIs | MDN
1 Like
I didn’t get the solution on there
The Element.remove() method doesn’t take any parameters. Just call it on the instance of an element you want to remove.
Element.parentElement is a property that is accessible on all elements in the document. It’s accessed the same way as any other object property.
Chain them together on the button element to remove its parent.
In all fairness, it doesn’t really explain how to use the method. Not sure if it has been explained previously.
As said, the .remove()
method is called on the element to be removed. In this case, the parentElement
of the button that was clicked.
<div>
<button onclick="removeParent(this)">Remove parent div</button>
</div>
function removeParent(btn) {
console.log(btn.parentElement); // div
btn.parentElement.remove();
}
2 Likes
Thank you so much i got it
1 Like
system
Closed
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.