Can't remove iframe by class rather than ID

I’m trying to unload an iframe so it stops video playing.

This works but I want to use classes instead as I don’t want to create unique id’s for every video!

hypeDocument.getElementById("vimeovideo1").innerHTML = ' '

I tried these but none work:

hypeDocument.getElementsByClassName("vimeovideo").innerHTML = ' '

and

hypeDocument.getElementById(hypeDocument.documentId()).getElementsByClassName("vimeovideo").innerHTML = ' '

Help apprecieted.

1 Like

I would use jQuery if you want to grad elements by class.

Ok so how would I do that?

I need it to be part of hype and not called up externally in html page though.

jquery-2.1.3.js.zip (72.4 KB)

Drop this into the resources file, and make sure its ticked at the bottom to include in the header, and then use something like:

$('.vimeovideo').text('');

Ta. That did the job. Shame have to load the resource but at least it works for classes now. Cheers.

This will give you an array of all elements with this classname. You'll have to loop this thru like:

var i
var vElements = document.getElementsByClassName("vimeovideo")
for (i = 0; i < vElements.length; i++) {vElements[i]. innerHTML = '';}

Nice. That works too!

can someone explain where to add this code exactly? Many thanks!

You would put this in a function and call it whenever you want. Say on mouse click of an element.

But, I wouldn’t just empty the contents. I would use the video.pause method but hey that’s just me.

How to display video again? help me please.