Inserted input type = "radio" tags with your data-group attribute:

<input type="radio" id="id1" data-group="group1"> <input type="radio" id="id2" data-group="group1"><br> <input type="radio" id="id3" data-group="group2"> <input type="radio" id="id4" data-group="group2"><br> 

As for all elements of input type = "radio", in which the data-group is equal to "group1", set checked = false?

  • @Etki, how is it nothing to worsen? Yes, I would have a duel for it :) He has flaws, sometimes very critical, but this is how “Doctor House” is among the medical series - one of many, but clearly stands out as the leader in all respects. jQuery provides a JS - программист interface, but, as you know, interfaces should not replace native code. In the depths of the nucleus, manipulations take place, which, on the one hand, implicitly carry out cross-browser compatibility, on the other hand, deprive the freedom of action of IMHO. - user31688
  • @sitev_ru, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - user31688

1 answer 1

 var group = document.querySelectorAll('input[type="radio"][data-group="group1"]'); [].forEach.call(group, function(e){ el.checked = false; }); 
  • I ’ll add an example to jquery - jsfiddle.net/a472sfy2 $ ('input: radio [data-group = "group1"]'). Attr ('disabled', 'disabled') - xFloooo
  • one
    @xfloooo, aaaa, dude, connecting jQuery for such a simple operation is a sin, worse than which it is difficult to find anything! We got these non-coders, who climb with this filth everywhere, the native JS do not know at all! Damn, bombanulo, sorry :) - user31688
  • 2
    > ahhh, dude, connecting jQuery for such a simple operation is a sin, worse than which it’s hard to find anything! dudes, twenty-first century, stop saving on matches. a copy of cdn is practically guaranteed to roll around the client in the browser by connecting one library, you will almost guaranteed protect yourself from possible pending crutches browser and ensure easy expansion. Never will any script consist entirely of such an example, and when it comes to the wall of nonextensibility, you will have to to rewrite two hundred lines on jquery just like that, from personal pride - etki
  • one
    @TheDoctor, it's somehow wasteful to create an array, just to not write 'Array.prototype'. - dzhioev
  • one
    > that some wonder that jQuery is not native JS? ummm .. in this case everything that is written on js is not native js ... (in the sense that if non-originality should strain) - zb '16