最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect HTML5 video tag - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

5 Answers 5

Reset to default 6

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
  }

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.
}
发布评论

评论列表(0)

  1. 暂无评论