Skip to content
Advertisement

SetAttribute on a specific position in Javascript

I have the following iframe

JavaScript

When I target iframe through getElementsByTagName like this

JavaScript

It returns:

JavaScript

It’s creating a problem for me because it is not working as expected. When I manually insert allowfullscreen at beginning it’s working well.

This is the result I want instead

JavaScript

What am I doing wrong?

Advertisement

Answer

One simple way to add allowfullscreen="" just after the tag name is to modify the outerHTML of the element using string method split and array method splice as in the code below.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement