JavaScript Getting HTML value into a Javascript function getting html value in jquery,html getting value from input

There is a string value in a p class like <p id="demo">10 hours : 25 minutes : 20 seconds</p>. Here I want to split that value like 10:25:20. This is my javascript function.

function countdownTimeStart(){
   var countDownDate = new Date("Mar 5, 2018 15:37:25").getTime();

   var x = setInterval(function() {
     something ... 
   }

So I need to replace the var countDownDate = new Date("Sep 5, 2018 15:37:25").getTime(); into above 10:25:20 which comes from p tag. I'm tried following way.

var countDownDate = document.getElementById("demo").value;

But it does not work. Can anyone help me to solve this.

Answer:1

You need to access the text content of the element there. .value only works for inputs and textareas.

const digits = document.querySelector('#demo').textContent.match(/\d\d/g);
const time = digits.join(':');
console.log(time);
<p id="demo">10 hours : 25 minutes : 20 seconds</p>
Answer:2

div doesn't have a value, it has innerHTML and textContent which can be get/set

var countDownDate = document.getElementById('demo').textContent;
Answer:3

So I am using readline-sync to perform basic calculations. Multiplying and dividing work fine, but when I add both numbers it just concatenates them and when I subtract it returns NaN. Any idea what ...

So I am using readline-sync to perform basic calculations. Multiplying and dividing work fine, but when I add both numbers it just concatenates them and when I subtract it returns NaN. Any idea what ...

  1. addition subtraction working model
  2. addition subtraction working wall
  3. addition and subtraction worksheet
  4. addition and subtraction working wall ks2
  5. addition and subtraction working wall year 3
  6. addition and subtraction working wall year 2
  7. addition and subtraction work mat
  8. addition and subtraction working wall year 1
  9. addition and subtraction working wall year 4
  10. addition and subtraction maths working wall

The javascript Date object parse method is "optimistic", that is, it fills in information that is missing with the earliest possible date. e.g. new Date('January 2016'); // = Jan 01 2016 new Date('...

The javascript Date object parse method is "optimistic", that is, it fills in information that is missing with the earliest possible date. e.g. new Date('January 2016'); // = Jan 01 2016 new Date('...

I have 2 div lines, each of them has 4 tabs. If I open one tab in one of the divs, I want the other div tabs to be closed. How can I do that? This is my code (see it live also on codepen): $(...

I have 2 div lines, each of them has 4 tabs. If I open one tab in one of the divs, I want the other div tabs to be closed. How can I do that? This is my code (see it live also on codepen): $(...

  1. instagram
  2. italy
  3. indeed
  4. ikea
  5. iphone 11
  6. instacart
  7. icloud
  8. italy news
  9. i still believe
  10. imdb
  11. impeachment
  12. ihop
  13. internet speed test
  14. iready
  15. iphone 11 pro max
  16. itunes
  17. infinite campus
  18. instant pot

Following the guide, I came to a sorts of middlewares are there for redux application. Redux Thunk, Redux Promise, Redux Promise Middleware, Redux Observable, Redux Saga, Redux Pack It is just a ...

Following the guide, I came to a sorts of middlewares are there for redux application. Redux Thunk, Redux Promise, Redux Promise Middleware, Redux Observable, Redux Saga, Redux Pack It is just a ...