Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial2pd
8,123 PointsTask 8: Remove '.extra' <div> element from DOM when user clicks button
If the below doesn't make sense, you can look at my Workspace: https://teamtreehouse.com/workspaces/42051290
I can't figure out why my code isn't working. It's //8 that's tripping me up.
// 7: Create a <button> element, and set its text to 'Delete' Add the <button> inside the '.extra' <div>
const delButton = document.createElement('button');
delButton.textContent = 'Delete';
document.querySelector('.extra').append(delButton);
// 8: Remove the '.extra' <div> element from the DOM when a user clicks the 'Delete' button
delButton.addEventListener('click', removerFunc){
function removerFunc(){
const removeDiv = document.querySelector('.extra');
removeDiv.remove();
}}
IDK what's wrong with my Markdown, sorry.
2 Answers
Steven Parker
231,269 PointsTo display a code block in markdown (as shown below), put it between lines with 3 accents (```). You might want to watch this video on code formatting.
And you can't share a direct URL to your workspace, it's temporary and only exists while you are using it. But you can use the snapshot function in the workspace and provide the link to that.
The syntax of the code in step 8 is a bit off, and the callback function can be anonymous:
delButton.addEventListener("click", function () {
const removeDiv = document.querySelector(".extra");
removeDiv.remove();
});
2pd
8,123 PointsThanks so much for your help, Steven Parker
I did put the code between three backticks on each side but it broke the formatting. I'll have a look at the Markdown guide again ...
Need more practice with functions ...