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>
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>
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>
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>