Let's suppose i have an array of words
JS
var fruit = [banana, apple, watermelon, mango];
function loadFruit() {
var randomFruit = fruit[Math.floor(Math.random() * fruit.length)];
$('.divLoadFruit').parent('div').html(randomFruit);
};
I need to trigger function on click of the middle word of the sentence, to obtain different random matches
HTML
"You need to eat <a href='javascript: loadFruit();'>just_some_fruit</a>: it is good for your health."
"My son doesn´t like <a href='javascript: loadFruit();'>another_fruit_here</a>."
When you click on one of the links, it triggers the same function (obviously) but gets me the same fruit in that spaces. Is there any way to make it random without repeating?
Aucun commentaire:
Enregistrer un commentaire