I have problems with my javascript. I need to match the image in a specific position. The user gives me a date, and I put the image on the correct month of the year. For example, if they put 01/05/1936, the image appears in the table in the line "1936" on colummn "5", so I have 2, each of them for several years. The month is correct, but it puts the image in all lines, and I don’t know why, here is my code:
In the HTML part, I have a table with id="tabla"and 2 rows, one s id="1935", and the other s id="1936", each tdhas a class of the correct month:
<tr id="1935">
<th>1935</th>
<td class="E"></td>
<td class="F"></td>
<td class="M"></td>
<td class="A"></td>
<td class="Y"></td>
<td class="J"></td>
<td class="L"></td>
<td class="G"></td>
<td class="S"></td>
<td class="O"></td>
<td class="N"></td>
<td class="D"></td>
</tr>
<tr id="1936">
<th >1936</th>
<td class="E"></td>
<td class="F"></td>
<td class="M"></td>
<td class="A"></td>
<td class="Y"></td>
<td class="J"></td>
<td class="L"></td>
<td class="G"></td>
<td class="S"></td>
<td class="O"></td>
<td class="N"></td>
<td class="D"></td>
</tr>
`Javascript code
var filas=document.getElementById("tabla").rows.length;
var cols = $("#tabla").find('tr')[0].cells.length;
$("tr").each(function(a){
var fila= $(this);
alert("Primer alert"+fila.attr("id"));
if (fila.attr("id")==anio)
{
$("td").each(function(a)
{
var col=$(this);
alert("segundo alert"+col.attr("class"));
if (col.attr("class")==mon)
{
$(this).prepend('<img id="black_point" src="./images/circle.png"/>');
}
});
}
});`
source
share