0

I need a javascript that can read the value of this:

<div id="timer" >07.45</div>    

,it's a timer and it counts from 20 seconds, it counts down in seconds and miliseconds , so how can I get let's say 07.45 value to be shown! This is what I tried but it doesn't work, it shows undefined

<div id="timer">07.45</div>    
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("timer").value;
document.getElementById("demo").innerHTML = x;}
</script>
5
  • 1
    Welcome to StackOverflow! The format here is that of a question and answer site, and in order for a question to be valid we need to know what it is your trying to do(check), what your end result should be(check), and what you have tried(please add). Your question could use a bit better formatting as well! Commented Mar 14, 2018 at 17:29
  • what do you mean "I need a javascript that can read the value of this" ? don't you know how to do a simple "document.getElementById('timer')" Commented Mar 14, 2018 at 17:29
  • Welcome to SO, please take the tour and read through the help center, in particular How do I ask a good question? Do your research, search for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a Minimal, Complete, and Verifiable example of your attempt and say specifically where you're stuck. People will be glad to help. Commented Mar 14, 2018 at 17:30
  • 5
    I'm voting to close this question as off-topic because the effort the OP put into researching / trying is too low to be acceptable Commented Mar 14, 2018 at 17:31
  • Generally speaking, div elements don't have values. You might want the innerHtml instead. Commented Mar 14, 2018 at 18:46

1 Answer 1

1

if I understand your question,

you're having trouble with the reading of value.

function myFunction() {
document.getElementById("demo").innerHTML = document.getElementById("timer").innerHTML;
}

You can also read some DOM documentation around the web. Hope can help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.