Try the following, which will correctly display the counter for the selected values.
$(document).ready(function() {
JSFiddle example
Note. This will result in a countdown sequence for each element that has the countdown class. If you want to make it more restrictive for a single element, you need to change the selector from .countdown to something more restrictive. The easiest way is to add an id and directly reference the element.
<p id='theTarget'>15</p>
JavaScript is a bit more complicated here because you want the timer to be eventually turned off, as there wasnโt much chance or use of an element with a duplicate identifier added.
$(document).ready(function() { var timer = setInterval(function() { var count = parseInt($('#theTarget').html()); if (count !== 0) { $('#theTarget').html(count - 1); } else { clearInterval(timer); } }, 1000); });
JSFiddle example
source share