-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOM4.html
55 lines (43 loc) · 1.24 KB
/
DOM4.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
background: #dddddd;
display: inline-block;
margin-right: 10px;
border: 1px solid #AAAAAA;
}
.azul{
background: #0074D9;
border: 1px solid #000;
}
.rojo{
background: #c21a11;
border: 1px solid #000;
}
</style>
</head>
<body>
<h1>Acceso a los atributos del DOM</h1>
<section id="contenedor">
<a href="https://aprendejavascript.org/" id="enlace">Pagina web</a>
<div class=""></div>
<div class=""></div>
</section>
<script>
// creando un nuevo elemento
var elemento = document.createElement("div");
var padre = document.getElementById("contenedor");
var referencia = document.getElementsByTagName("div")[0];
elemento.setAttribute("class",'azul');
padre.insertBefore(elemento, referencia);
</script>
</body>
</html>