-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·47 lines (36 loc) · 1.4 KB
/
Copy pathscript.js
File metadata and controls
executable file
·47 lines (36 loc) · 1.4 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import{barcelona, roma, paris,londres} from './ciudades.js'
// obtener los elementos del dom
let enlaces = document.querySelectorAll('a')
let tituloElemento = document.getElementById('titulo')
let subTituloElemento = document.getElementById('subtitulo')
let parrafoElemento = document.getElementById('parrafo')
let precioElemento = document.getElementById('precio')
// agregar un evento click a cada enlace
enlaces.forEach ( function(enlace) {
enlace.addEventListener('click', function(){
// remover la clase active de todos los enlaces
enlaces.forEach( function (enlace){
enlace.classList.remove('active');
}
);
// agregar clase active al enlace actual
this.classList.add('active')
// obtener el contenido correspondiente segun el enlace
let contenido = obtenerContenido(this.textContent)
// mostrar el contenido en el dom
tituloElemento.innerHTML = contenido.titulo
subTituloElemento.innerHTML = contenido.subtitulo
parrafoElemento.innerHTML = contenido.parrafo
precioElemento.innerHTML = contenido.precio
}) ;
});
// funcion para traer la informacion correcta desde ciudades.js
function obtenerContenido(enlace){
let contenido = {
'Barcelona' : barcelona,
'Roma' : roma,
'París' : paris,
'Londres' : londres
};
return contenido [enlace];
}