Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!