Problems with id in script

0

I have this input

@foreach (var j in jornada){
<input id="jor" name="NombrJornada" type="radio" value="@j.IdJornada" onclick="Filtro"/>
}

and my script I have this

$(function() {
        $("#jor").click(function () {
            console.log("Hola");
        });
    });

The problem is that my script only runs on a single radio button could you help me solve this problem?

    
asked by JPerez 09.02.2018 в 18:28
source

1 answer

2

replace in your HTML:

<input id="jor" name="NombrJornada" type="radio" value="@j.IdJornada" onclick="Filtro"/>

By:

<input class="jor" name="NombrJornada" type="radio" value="@j.IdJornada" onclick="Filtro"/>

and in your JavaScript:

$(function() {
            $("#jor").click(function () {
                console.log("Hola");
            });
});

By:

$(function() {
            $(".jor").click(function () {
                console.log("Hola");
            });
});

Explanation:

You can only have 1 single ID for 1 element, in case multiple elements have the same ID, the listener events (event listeners) will work only in 1. You can have multiple classes, the jQuery selector uses a period instead of a michi (#).

    
answered by 09.02.2018 / 18:35
source