Last active
August 29, 2015 14:19
-
-
Save turboMaCk/08adc1c96b8f5728dab7 to your computer and use it in GitHub Desktop.
radios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <input type="radio" name="aasd"> | |
| <input type="radio" name="aasd"> | |
| <input type="radio" name="aasd"> | |
| <input type="radio" name="aasd"> | |
| <input type="radio" name="aasd"> | |
| <input type="radio" name="aasd"> | |
| <br> | |
| <input type="radio" name="aasd2"> | |
| <input type="radio" name="aasd2"> | |
| <input type="radio" name="aasd2"> | |
| <input type="radio" name="aasd2"> | |
| <input type="radio" name="aasd2"> | |
| <input type="radio" name="aasd2"> | |
| <script> | |
| function groupRadios() { | |
| // ram eaters | |
| var result = []; | |
| var radios = document.querySelectorAll('input[type=radio]'); | |
| var name; | |
| // loop all radios | |
| [].forEach.call(radios, function(radio) { | |
| // cache name of current | |
| name = radio.getAttribute('name'); | |
| // if nothing is store under this name create new group | |
| if (result[name] == undefined) { | |
| result[name] = []; | |
| } | |
| // add radio to its goup | |
| result[name].push(radio); | |
| }); | |
| // return of the Jedi | |
| return result; | |
| } | |
| // call and log | |
| var radioGroups = groupRadios(); | |
| console.log(radioGroups); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment