Como acessar a propriedade data-weekday do elemento div com javascript?
<div style="display: none;" id="weekday" data-weekday="7"></div>
Pode usar o .dataset
:
const weekDay = document.getElementById('weekday').dataset.weekday;
console.log(weekDay); // 7
<div style="display: none;" id="weekday" data-weekday="7"></div>
Ou ler o atributo diretamente:
const weekDay = document.getElementById('weekday').getAttribute('data-weekday');
console.log(weekDay); // 7
<div style="display: none;" id="weekday" data-weekday="7"></div>
Para pegar um atributo da sua div basta usar getAttribute("data-weekday");
especificado no w3schools. Segue a demo.
var x = document.getElementById("weekday").getAttribute("data-weekday");
alert(x);
<div style="display: none;" id="weekday" data-weekday="7"></div>
Com Jquery
var x = $("#weekday").attr("data-weekday");
alert(x);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="display: none;" id="weekday" data-weekday="7"></div>