$(document).ready(function(){ var quoteSource=[ { quote: "Forgefroide de Missiz Frizz", name:"Missiz Frizz" }, { quote:"Transporteur de Sylargh", name:"Sylargh" }, { quote:"Salons privés de Klime", name:"Klime" }, { quote:"Laboratoire de Nileza", name:"Nileza" }, { quote:"Donjon du Comte", name:"Comte Harebourg" }, { quote:"Aquadôme de Merkator", name:"Merkator" }, { quote:"Palais du roi Nidas", name:"roi Nidas" }, { quote:"Trône de la Cour Sombre", name:"Reine des Voleurs" }, { quote:"Ventre de la Baleine", name:"Protozorreur" }, { quote:"Œil de Vortex", name:"Vortex" }, { quote:"Défi du Chalœil", name:"Chalœil" }, { quote:"Vaisseau du Capitaine Meno", name:"Capitaine Meno" }, { quote:"Temple de Koutoulou", name:"Larve de Koutoulou" }, { quote:"Palais de Dantinéa", name:"Dantinéa" }, { quote:"Chambre de Tal Kasha", name:"Tal Kasha" }, { quote:"Manoir des Katrepat", name:"Anerice la Shushess" }, { quote:"Belvédère d'Ilyzaelle", name:"Ilyzaelle" }, { quote:"Tour de Solar", name:"Solar" }, { quote:"Tour de Bethel", name:"Bethel Akarna" }, { quote:"Brasserie du roi Dazak", name:"Dazak Martegel" }, { quote:"Fouyaya. Les donjons de ce niveau sont bien trop difficiles pour toi !", name:"La Voix de la Raison" } ]; $('#quoteButton').click(function(evt){ //define the containers of the info we target var quote = $('#quoteContainer p').text(); var quoteGenius = $('#quoteGenius').text(); //prevent browser's default action evt.preventDefault(); //getting a new random number to attach to a quote and setting a limit var sourceLength = quoteSource.length; var randomNumber= Math.floor(Math.random()*sourceLength); //set a new quote for(i=0;i<=sourceLength;i+=1){ var newQuoteText = quoteSource[randomNumber].quote; var newQuoteGenius = quoteSource[randomNumber].name; //console.log(newQuoteText,newQuoteGenius); var timeAnimation = 500; var quoteContainer = $('#quoteContainer'); //fade out animation with callback quoteContainer.fadeOut(timeAnimation, function(){ quoteContainer.html(''); quoteContainer.append('
'+newQuoteText+'
'+''+'- '+newQuoteGenius+'
'); //fadein animation. quoteContainer.fadeIn(timeAnimation); }); break; };//end for loop });//end quoteButton function });//end document ready