0

http://jsfiddle.net/8sbt5oua/8/

I would like to get my code only concentrated on a few everytime.
Instead of all of them, who could help me?

gif

    <input id="01" type="radio">
    <input id="02" type="radio">
    <input id="03" type="radio">
    <input id="04" type="radio">
    <input id="05" type="radio">
    <input id="06" type="radio">


var btn = document.getElementById("02");
setInterval(function() {
  var list=document.getElementsByTagName("input");
  for (i=0;i<list.length;i++) {
    btn = list[i];
    btn.checked == false ? btn.setAttribute("checked", "checked") : btn.removeAttribute("checked");
  }
}, 500);
2
  • why is your jsfiddle not clickable? Commented Dec 11, 2016 at 11:38
  • What do you wish to accomplish with this code ? What should this line do : var btn = document.getElementById("02"); ? Commented Dec 11, 2016 at 12:52

1 Answer 1

1

Here's the JsFiddle: http://jsfiddle.net/8sbt5oua/10/

First have two arrays that you want to flicker on and off.

var arr1 = [0,1,2];
var arr2 = [3,4,5];

You also want a global variable that toggles between the two.

var use_first = true;

Then you want to use the toggling variable to determine which one toggles on and which ones toggles off.

let remove;
let checked;

if (use_first)
{
    checked = arr1;
  remove = arr2;
}
else
{
    checked = arr2;
  remove = arr1;
}

And I think the foreach explains themselves since they're basically your code.

Edit:

remove.forEach(function(item, index)
{
    btn = list[item];
  btn.removeAttribute("checked");
});
checked.forEach(function(item, index)
{
    btn=list[item];
  btn.setAttribute("checked", "checked");
});
Sign up to request clarification or add additional context in comments.

5 Comments

How can I "not" randomize this but say the first time, only button 02, 03, 06, second time 01, 04, 05. I would like to make a whole page of these buttons but want to precisely say which sound blink and which shouldn't because I also want a few to not blink at all. (they will become an image at the end, so I need to precisely say which should blink.)
Updated. Let me know if you need more explanation
Is there a possibility that the code doesn't work in Safari?
Can't say, I don't own a mac.
Then another question, If I want to do for example in var arr1 = [1,2,3] and in var arr2 = [2,4,6] the 2 doesn't show up, how could I fix that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.