hi i am trying to rotate a field inside variable in javascript this is a part of a code: var a = { sr: 22, id: 31, jab:45124, domain: 'aaa.com' }; i am trying to rotate the domain field : aaa.com with bbb.com and/or ccc.com i already tried rotating it in many ways including all the rotate methods for images banners etc but no luck so far. how can i do it? -also tried rotating the whole line "var a ....." but i couldn't do it too thanks
Perhaps something like this: <!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> var a = { "sr": 22, "id": 31, "jab": 45124, "domain": [ "aaa.com", "bbb.com", "ccc.com" ] }; var which = 0, show, len; function rotateDomain() { show.innerHTML = a["domain"][which]; which = ++which % len; // which = Math.floor(Math.random()*len); // or randomized alternative setTimeout(rotateDomain, 3000); } window.onload = function() { show = document.getElementById("showit"); len = a["domain"].length; rotateDomain(); } </script> </head> <body> <div> <a href="#" id="showit"></a> </div> </body> </html> Code (markup):