Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser events #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const mainHeading = document.querySelector("h1");

mainHeading.addEventListener("mouseover", function () {
mainHeading.textContent = "Build an AR app";
});
mainHeading.addEventListener("mouseleave", function () {
mainHeading.textContent = "Learn ARKit";
});

// exercise event listener
const heroModule = document.querySelector(".hero__module");

function removeModuleChild() {
heroModule.lastElementChild.remove();
document.removeEventListener("click", removeModuleChild);
}

document.addEventListener("click", removeModuleChild);

// add favorites exercise
const nanoCardTitle = document.getElementsByClassName(
"card--nanodegree__title"
);

// adds button under title for each card
for (const card of nanoCardTitle) {
// creates btn for each card
const button = document.createElement("button");
button.textContent = "Add to Favorites";
button.classList.add("button");
button.classList.add("button--primary");
card.appendChild(button);

// click event
button.addEventListener("click", function (e) {
// defaults
e.preventDefault();
e.target.classList.toggle("favorite");
console.log(e.target.classList.contains("favorite"));

// star element
const stars = document.createElement("p");
stars.textContent = "🌟🌟🌟";

// toggle logic
if (e.target.classList.contains("favorite")) {
e.target.textContent = "Remove from favorite";
e.target.appendChild(stars);
} else {
e.target.textContent = "Add to Favorites";
stars.remove();
}

//
});
}