-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscript.js
More file actions
17 lines (14 loc) · 804 Bytes
/
Copy pathscript.js
File metadata and controls
17 lines (14 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function domManipulation() {
const description = document.getElementById("description"); // <div> de description
const textNode = description.children[0]; // obtenir l'élément <p>
const button = textNode.nextElementSibling; // prochain élément : le bouton
button.click(); // lancer l'événement de click sur le bouton
textNode.textContent = "Cours 1 - HTML"; // modifie le contenu du texte
const newElement = document.createElement("p"); // créer un nouveau élément
newElement.textContent = "Modifier le DOM avec JS!"; // ajouter du texte
document.body.appendChild(newElement); // rajouter comme enfant à body
}
window.onload = () => {
const domButton = document.getElementById("domManipulator");
domButton.addEventListener("click", domManipulation);
}