lundi 28 août 2017

Execute a function when pressing a button in jQuery

I am quite new to programming, and have met a problem.

I really want to run this function, when I press a button. Here is the function that I want to run:

function generateTip() {
var tip = tipsList[generateNumber()];
var tipElement = document.querySelector('.js-tip');

tipElement.innerHTML = tip;

}

Alright, I want to run this function, when pressing a button, and here is the code for my jQuery button:

$(document).ready(function(){
$('button').click(function() {
  //run function here 

}); });

It doesn't have to be jQuery, I just thought that would be easier. I would be very grateful if somebody would help and explain.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire