getElementById for a noob
I'm trying really hard to learn JS, but it just isn't going well.
That said, here's what I'm trying to do. I have a client who wants to say something to the effect that he's been performing magic for x years. I'd like to create a script that, if I input the date he started performing, would calculate the number of years since, so it won't need to be updated in the future.
I've found and edited the following script to that end:
I understand what's going on here.
However, I'd like, instead of writing the answer with document.write, to target a span using getElementById. ...And that's where I'm lost.
Please help
I'm trying really hard to learn JS, but it just isn't going well.
That said, here's what I'm trying to do. I have a client who wants to say something to the effect that he's been performing magic for x years. I'd like to create a script that, if I input the date he started performing, would calculate the number of years since, so it won't need to be updated in the future.
I've found and edited the following script to that end:
Code:
<script type="text/javascript">
var millennium =new Date(1971, 3, 25);
today=new Date();
var one_day=1000*60*60*24*365;
document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))
</script>
I understand what's going on here.
However, I'd like, instead of writing the answer with document.write, to target a span using getElementById. ...And that's where I'm lost.
Please help
Last edited: