How to I loop through the elements retrieved using document.getElementsByTagName(); as it's length is coming out to be 0 but still has elements.
Below is the JS code:
class HKPlayer
{
constructor()
{
this.getPlayers();
this.getPlayerAttributes();
}
getPlayers()
{
this.players = document.getElementsByTagName("HKPlayer");
}
getPlayerAttributes()
{
console.log(this.players);
}
}
(function () {
new HKPlayer();
})();
below is the html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HKPlayer Demo</title>
<script src="dist/HKPlayer.js" type="text/javascript"></script>
</head>
<body>
<HKPlayer type="video" theme="dark" src="assets/video/1.mp4"></HKPlayer>
<br/>
<HKPlayer type="video" theme="dark" src="assets/video/2.mp4"></HKPlayer>
</body>
</html>
The output is like:
I cannot loop through this.players
as the array this.players array is empty. how do I do that.