0

I'm trying to make a stopwatch in Javascript and HTML. I got all the buttons and the stopwatch itself working but there is just one thing I can't understand how to do. When I press the lap button I wan't to print the laptime in a new paragraph in my HTML document.

So if I press the lap button I want the time to show up in a list under and if I press it again I want it to show up under the last time and so on. But I can't just understand how to do.

I'm glad for all the help!

//Villevillekulla

  • show us your code! Best put it on jsfiddle. – k-nut Nov 05 '14 at 20:47
  • 1
    No, it's *essential* (and therefore 'best') to *show code here in the question*; live demos are a bonus, and do help, but they are not the 'best' by any stretch. – David Thomas Nov 05 '14 at 20:48
  • Or also possibly http://stackoverflow.com/questions/5677799/how-to-append-data-to-div-using-javascript, or a million other questions. – Sam Hanley Nov 05 '14 at 20:49

2 Answers2

0

Some code would be helpful, but I imagine you'll want something close to this:

var laptime_val = '2:23';

var laptime_el = document.createElement('p');
document.body.appendChild(laptime_el);

laptime_el.innerHTML = laptime_val;
elzi
  • 5,442
  • 7
  • 37
  • 61
  • @Villevillekulla remember to select the answer that worked for your so the submitter is awarded the answer. – elzi Nov 06 '14 at 18:24
0

Check this stopwatch.

Html:

<button id="lap">Lap</button>
<div id="screen"></div>

JS:

$(document).ready(function(){
    var time = 0;
    var timer;

    $('#lap').click(function(){
        if (!timer){
            timer = setInterval(function(){
                time+=0.010;
                $("#screen p:last").text(time.toFixed(2));
            },10);
        }
        $("#screen").append('<p>'+time+'</p>');

    });
});
Sampath Liyanage
  • 4,776
  • 2
  • 28
  • 40