Grimoire-
Command
.es

GNU+Linux command memo

Access datetime attribute of HTML time tag via JavaScript

Accès à l’attribut datetime de la balise HTML time via JavaScript

>> var a = document.querySelector('time')
>> console.log(a)
<time datetime="2022-03-29T14:17:57+02:00">
>> a.getAttribute('datetime')
"2022-03-29T14:17:57+02:00"
>> a['datetime'] (1)
undefined (2)
>> a['dateTime'] (3)
"2022-03-29T14:17:57+02:00"
>> a.attributes['datetime'].value (4)
1 The Array notation is faster to access attributes (and compact)
2 But this attribute is suddenly undefined ?
3 It has an alternative name when you access it this way (note the 'T' instead of t)
4 Regular HTML tag attributes are stored in the attributes property. dateTime is just an exception. A better notation, the one preferred in Meta-Press.es is : a.attributes.datetime.value