Post

jQueryjQuery

A
Altaf syed

Posted on 27th February 2024|456 views

0
votes

Jquery Set Radio Button Checked By Id

how to Set radio button 'checked' in jquery based on ID?

in my program, there are two radio buttons in which one radio button is checked by default. Still, my question is how to uncheck or check a radio button within jQuery when selecting by id the program is:

$(‘#radioA’).attr(‘checked’,’checked’);

$(‘#radioA’).attr(‘checked’,’true’);  

Can you please help me?

 

Answers
P
veerubhotla sowmithri

Posted on 27th February 2024

We should not use the same id more than once instead we can use class 

$(‘.radioA’).attr(‘checked’,’true’);

$(‘.radioB’).attr(‘checked’,’true’);

The id must be utilised one per the element per page

$('#id').click(function(){ 

$('#radioA').attr('checked', true); 

});

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos