Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
How to access element through variable ID in Jquery

I am writing a code where I want to check a radio button through Jquery, there are some links, when I click on a specific link it checks a radio button , Id of radio button is passed to jquery click function, I get that id and store it in variable , how to access that radio button element through var id!!!!

//Html
<ul class="footer-links">
  <li>Services</li>
  <li><a href="#scrollup-content" data-id="tab-1">Brand Management</a></li>
  <li><a href="#scrollup-content" data-id="tab-2">In & Outdoor Signage</a></label></li>
</ul>

//jquery
$(".footer-links li a").on("click",function(){
        var id = $(this).data();
        console.log(id)
        $('#tab-2').attr('checked', true); // this is working properly
        $('#id').attr('checked', true);// how to do? I want this to work
    })
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think there is a problem with the elements in the HTML part: I can't see that you have added a radio button to the file. Check out the sample code below:

$('#radioButtonForm input').on('change', function() {
   alert($('input[name=radioName]:checked', '#radioButtonForm').val()); 
});
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <title>Test Project</title>
</head>

<body>
    <form id="radioButtonForm">
        <ul>
            <li>Services</li>

            <li>
                <input type="radio" name="radioName" value="1" />Brand Management<br />
            </li>

            <li>
                <input type="radio" name="radioName" value="2" />In&Outdoor Signage<br />
            </li>
        </ul>
    </form>
</body>

</html>

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda