JavaScript - Añadir Si El Elemento Cuyo Atributo Es Igual A Variable

 
Vista:
sin imagen de perfil

Añadir Si El Elemento Cuyo Atributo Es Igual A Variable

Publicado por Luis Sabi (24 intervenciones) el 13/02/2017 23:08:05
Buenas Gente, Lo Que Quiero es Agregar Los Elementos Cuyo Atributo 'data-date' Sean Igual A La FechaActual A Un Div Que Se Denomina Hoy. Agradecería Su Ayuda.

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
<script>
 
 
	function ocultarPorFecha() {
	var fechaActual = new Date();
	// 2) RECUPERO TODOS LOS TR QUE TIENE LA CLASE .date-team
 
	var partidos = document.querySelectorAll('tr.date-team'); // => devuelve un NodeList
	partidos = Array.prototype.slice.call(partidos); // 3) Convierto el NodeList en un Array para poder recorrerlo
 
	// 4) Utilizo el metodo forEach para recorrer el array
	partidos.forEach(function(element, index) {
 
		var fechaInicioPartido = element.getAttribute('data-date'); // 5) obtengo la fecha del partido 
		fechaInicioPartido = construyeFecha(fechaInicioPartido); // 6) covierto la fecha con tu funcion
 if (fechaActual > fechaInicioPartido){
	   element.style.display = "none" ;
  }
  var fechasIguales = fechaInicioPartido == fechaActual;
 
	if (fechasIguales = true){
 
		$('.Aquí').append(element.getAttribute('data-date') === fechaActual.getDate() ());
 
/*
Aquí, Por Encima De Este Comentarió Es Donde Creo Estoy errado, No Logro Dar Con Los Elementos. 
Si  Pongo Este Código, Se Agregan Todos Los Elementos. 
   
$('.Aquí').append(element); 

Y No Es Lo Que Deseo. 



*/
 
	}
	});
}
 
 
function construyeFecha(stringfecha) {
	var dia = parseInt(stringfecha.substring(0, 2));
	var mes = parseInt(stringfecha.substring(3, 5)) - 1;
	var anio = parseInt(stringfecha.substring(6, 10));
	var hora = parseInt(stringfecha.substring(11, 13));
	var minuto = parseInt(stringfecha.substring(14, 16));
	return new Date(anio, mes, dia, hora, minuto);
}
 
// 1) Agrego el manejador de eventos
window.addEventListener('load', ocultarPorFecha);
 
</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder