JavaScript How to set timing information directly into the DOM?

According to this link by mozilla, the data- attribute is used for setting data in the DOM. I want to grab the time using new Date().getTime() and append it to an element in the DOM.

What is the proper way to do this in JavaScript? It is just a simple div element and I want to set an attribute called data-time.

Pseduo code would be:

div_element.data-time = new Date().getTime();

Answer:1

If you are setting and getting the value using script, DOM properties are fine:

div_element['data-time'] = +(new Date());
Answer:2

You should use dataset API

divElement.dataset.time = new Date().getTime();

Support is not perfect though, so be aware. IE11+. If you need to support dinosaurs go with setAttribute way.

Answer:3

This site is probably overkill for the level of technical input I need for my query but the only other option is to ask Weebly support who are useless. Essentially I have a tracking pixel from google ...

This site is probably overkill for the level of technical input I need for my query but the only other option is to ask Weebly support who are useless. Essentially I have a tracking pixel from google ...

  1. adding tracking pixel to email
  2. adding tracking pixel to html
  3. adding a tracking pixel to website
  4. shopify adding a tracking pixel

I am working with dynamic web, this connected to websocket, then when my web load, i call a load.php (with angular directive). This web(load.php) makes a select in mySQL (i have many tables, linked ...

I am working with dynamic web, this connected to websocket, then when my web load, i call a load.php (with angular directive). This web(load.php) makes a select in mySQL (i have many tables, linked ...

This is my code: http://jsfiddle.net/Xk38X/6/ $('#register').click(function() { if( $('#company_f').val().length == 0 ) { $('#company_f').css("border", "solid 1px red"); } }); The ...

This is my code: http://jsfiddle.net/Xk38X/6/ $('#register').click(function() { if( $('#company_f').val().length == 0 ) { $('#company_f').css("border", "solid 1px red"); } }); The ...

  1. stop form submitting jquery
  2. stop form submitting on enter
  3. stop form submitting if validation fails
  4. stop form submitting using jquery
  5. stop form submitting javascript
  6. stop form submitting on page refresh
  7. stop form submitting
  8. stop form submitting twice
  9. stop form submitting on button click
  10. stop form submit on refresh php
  11. stop form submit js
  12. stop form submit jquery ajax
  13. stop form submit javascript validation
  14. stop form submit on enter javascript
  15. stop form submit on enter jquery
  16. stop form submit reloading page
  17. stop form submit on refresh
  18. stop form submit react
  19. stop form submit redirect
  20. stop form submit html

I'm currently working on a web application that is loaded inside an iframe inside a webview in a mobile app. As the user clicks a button, I perform an AJAX request, and once I get a successful ...

I'm currently working on a web application that is loaded inside an iframe inside a webview in a mobile app. As the user clicks a button, I perform an AJAX request, and once I get a successful ...

  1. redirect inside iframe not working
  2. redirect inside iframe
  3. redirect inside iframe javascript
  4. redirect page inside iframe
  5. php redirect inside iframe
  6. html redirect inside iframe
  7. redirect url inside iframe
  8. response.redirect inside iframe
  9. allow redirect inside iframe
  10. redirect page inside iframe javascript
  11. redirect in iframe not working