-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (26 loc) · 1.21 KB
/
script.js
File metadata and controls
33 lines (26 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Selecionando pelo ID do título
const title = document.getElementById("titulo");
// Selecionando o botão que exibe "Hello"
const helloBtn = document.getElementById("botao-ola");
// Selecionando o botão que altera o título
const changeTitleBtn = document.getElementById("btn-mudar-titulo");
// Evento de clique para exibir uma mensagem "Olá"
helloBtn.addEventListener("click", function () {
alert("Olá!");
});
// Evento de clique para alterar o texto do título
changeTitleBtn.addEventListener("click", function () {
title.textContent = "O Titulo foi mudado utilizando JS!";
});
// Selecionando os parágrafos com a classe 'mensagem2' (remover espaço)
const mensagens = document.getElementsByClassName('mensagem2'); // Correção aqui
// Criando o botão para modificar as frases
const botaomudarfrase = document.createElement('button');
botaomudarfrase.textContent = "Modificar a frase";
document.querySelector('.container').appendChild(botaomudarfrase);
// Evento de clique para modificar as frases
botaomudarfrase.addEventListener('click', function() {
for(let i = 0; i < mensagens.length; i++) {
mensagens[i].textContent = `Frase modificada ${i + 1} utilizando JS!`;
}
});