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
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
}
Use:
if($('video').length===0){
//video not found
}
if($("video").is(':visible')){
//do somthing
}
You can find HTML5 Video events here
尝试这个,
if($( "body:has(video)" ).length)
you can try this:
if($('video').length>0){
console.log('Video tag exists'); // do operations.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.