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
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
Share Improve this question asked Feb 3, 2014 at 6:31 Neha DanguiNeha Dangui 6573 gold badges15 silver badges29 bronze badges 2- IMHO I say, learn about javascript and the way objects work, the way DOM interaction can be achieved and then jump for JQuery. It's not a crime doing JQuery first, but you will love learning JQuery once you know javascript :) – Nagaraj Tantri Commented Feb 3, 2014 at 6:44
- Thanks for your suggestion. I will try to learn javascript first. – Neha Dangui Commented Feb 4, 2014 at 4:34
5 Answers
Reset to default 6You 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
}
Try this,
if($( "body:has(video)" ).length)
if($("video").is(':visible')){
//do somthing
}
You can find HTML5 Video events here
http://www.w3/2010/05/video/mediaevents.html
you can try this:
if($('video').length>0){
console.log('Video tag exists'); // do operations.
}