Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

onclick display array value javascript

var array = [1,20,50,100];
var cpt = 0;

//Init the 'par' div before click
document.querySelector("#par").innerHTML = array[cpt];

function randomQuote () 
{
  if(cpt<array.length-1)
    cpt++;
  else
    cpt=0;

  document.querySelector("#par").innerHTML = array[cpt];
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #onclick #display #array #javascript
ADD COMMENT
Topic
Name
5+1 =