0

Is it possible to select the below attribute 'time' in javascript in the same fashion as getElementById?

<div time="1537311600000" data-tooltip="" class="day toMonth  valid">19</div>
  • 4
    Yes: `[time=1537311600000]` would be the selector you'd use with `document.querySelector` –  Sep 21 '18 at 09:45

2 Answers2

1

Yes, you can access it with getAtribute

window.onload = function(){

console.log(document.getElementsByTagName("div")[0].getAttribute("time"));
console.log(document.getElementsByTagName("div")[0].getAttribute("data-tooltip"));

}
<div time="1537311600000" data-tooltip="" class="day toMonth  valid">19</div>
Turnip
  • 35,836
  • 15
  • 89
  • 111
Hary
  • 5,690
  • 7
  • 42
  • 79
0

querySelectorAll allows you to select on any attribute you like:

const timeToMatch = 1537311600000
const results = document.querySelectorAll(`[time="${timeToMatch}"]`)

console.dir(results)
<div time="1537311600000" data-tooltip="" class="day toMonth  valid">19</div>
OliverRadini
  • 6,238
  • 1
  • 21
  • 46