Javascript is not configured correctly

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;//I count the rows, years
    var cols = $("#tabla").find('tr')[0].cells.length;//I count the td, months


       $("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"/>');
                }
           });
        }
        });`
+4
source share
2 answers

jQuery .

, jQuery...

function foo(anio, mon) {
    $('#' + anio + ' .' + mon).prepend('<img id="black_point" src="./images/circle.png"/>');
}

, , .

+3

td , tr, :

$("td").each(function(a)

fila.find($('td')).each(function(a)
+2

All Articles