Skip to content
Open

DOM #50

Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions ex2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function getElementsByTagName(tag) {
const elements = document.getElementsByTagName("*");
const filteredElements = [];

for (let i = 0; i < elements.length; i++) {
if (elements[i].tagName === tag.toUpperCase()) {
filteredElements.push(elements[i]);
}
}

return filteredElements;
}

13 changes: 13 additions & 0 deletions ex3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Seleciona todos os elementos <img> da página
const images = document.getElementsByTagName("img");

// Itera sobre todas as imagens
for (let i = 0; i < images.length; i++) {
// Cria um novo elemento <span> contendo o texto de descrição da imagem
const altText = images[i].getAttribute("alt");
const span = document.createElement("span");
span.textContent = altText;

// Substitui a imagem pelo novo elemento <span>
images[i].parentNode.replaceChild(span, images[i]);
}
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>
Teste de Árvore DOM
</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.3.0/papaparse.min.js"></script>

<body>
<h1>Teste</h1>
<form>
<script src="main.js"></script>

<label for="csv-text">CSV:</label>
<br>
<textarea id="csv-text" rows="10"></textarea>
<br>
<button type="button" onclick="convertToTable()">Converter</button>
</form>

<div id="table-container"></div>
</body>

</html>
29 changes: 29 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function convertToTable() {
// Obter o texto do CSV a partir do campo de texto
const csvText = document.getElementById("csv-text").value;

// Analisar o CSV para obter uma matriz de dados
const data = Papa.parse(csvText).data;

// Criar a tabela HTML
const table = document.createElement("table");
const tbody = document.createElement("tbody");

// Adicionar as linhas da tabela
for (let i = 0; i < data.length; i++) {
const row = document.createElement("tr");

for (let j = 0; j < data[i].length; j++) {
const cell = document.createElement("td");
cell.textContent = data[i][j];
row.appendChild(cell);
}

tbody.appendChild(row);
}

// Adicionar a tabela ao contêiner
table.appendChild(tbody);
document.getElementById("table-container").appendChild(table);
}

70 changes: 70 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
text-align: center;
background-color: #c0bcbc;
}

h1 {
font-size: 36px;
font-weight: bold;
margin-bottom: 20px;
text-decoration: underline;
}

form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 30px;
}

label {
font-size: 1.2rem;
}

textarea {
width: 20%;
height: 150px;
margin-top: 10px;
padding: 10px;
font-size: 1.2rem;
border-radius: 5px;
border: 1px solid #ccc;
background-color: rgb(226, 221, 221);
}

button {
margin-top: 10px;
padding: 10px;
font-size: 1.2rem;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #3e8e41;
}

table {
margin: 0 auto;
border-collapse: collapse;
margin-top: 30px;
width: 20%;
}

td, th {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #4CAF50;
color: white;
}