I've found a curious inconsistency when working with HTML5 video.
Compare these two code snippets and take a look at the Elements tab in Chrome developer tools
<body>
<script>
const video1 = document.createElement('video');
video1.autoplay = true;
video1.muted = true;
document.body.appendChild(video1);
const video2 = document.createElement('video');
video2.setAttribute('autoplay', 'autoplay');
video2.setAttribute('muted', 'muted');
document.body.appendChild(video2);
</script>
</body>
For the first video
, muted
set using a JS object property wasn't set. For the second one, using setAttribute
worked and the DOM attribute is set. Interestingly, this is not the case for autoplay
where it behaves consistently.
Why is that? Is there another example of an attribute behaving this way? Is there a rule to this? How does one tell which attribute's property behaves which way in JS except for testing?