How to add an empty attribute to my video tag?

I would just like to add the autobuffer attribute to my video tag using javascript.

Mostly:

var video = document.createElement('video'); video.addAttribute('autoBuffer'); 

And I will have:

 <video autoBuffer></video> 

I tried:

 video.setAttribute('autoBuffer'); => <video autoBuffer="undefined"></video> 

What is wrong...

+4
source share
1 answer

The second setAttribute parameter should always be a string - currently undefined , which you implicitly pass, is converted to one. Use

 video.setAttribute('autoBuffer', ''); 
+6
source

Source: https://habr.com/ru/post/1489505/


All Articles