Reputation: 647
I had a query regarding HTML5 video tags. I wanted to know if there is any way to check if the text to be added in the body tag contains a HTML5 video tag using jQuery or javascript.
<video>
<source src="demo.mp4" type="video/mp4" />
<source src="demo.ogv" type="video/ogg" />
</video>
I cannot give any id or class to the video tag. I mean can we have something like
if($('body').contains('<video>')){
// do something
}
Thanks in advance.
Regards,
Neha
Upvotes: 1
Views: 2870
Reputation: 4934
you can try this:
if($('video').length>0){
console.log('Video tag exists'); // do operations.
}
Upvotes: -1
Reputation: 22395
You don't need jQuery for this, you can use getElementsByTagName()
var x = document.getElementsByTagName("video");
if (x.length) {
//do code if element(s) are present
}
Upvotes: 6
Reputation: 9542
if($("video").is(':visible')){
//do somthing
}
You can find HTML5 Video events here
http://www.w3.org/2010/05/video/mediaevents.html
Upvotes: 0