I have read through a few articles on how to add JavaScript to WordPress pages though it seems overly complex for what I need. I have this small script (see below) and I want it to work on just 1 page. I thought adding it within <script> tags after the main content would do the trick but I get the following error in the Console:
Uncaught TypeError: undefined is not a function
Even though the script works fine in the console, it doesn't work.
For this script do I have to use the complex methods or is there a simpler one?
$('#tSubmit').on('click', function() {
var amt = +$('#tCount').val(),
tier = $('#tType').val(),
h = +$('#tH').val() > 0 ? +$('#tH').val() : 0,
m = +$('#tM').val() > 0 ? +$('#tM').val() : 0,
s = +$('#tS').val() > 0 ? +$('#tS').val() : 0,
time = ((h*60+m)*60+s)/amt;
alert('Individual time for Tier ' + tier + ' troops: ' + time.toFixed(2) + ' seconds');
});
$withjQuery#tSubmitis clicked.