admin管理员组文章数量:1023251
Given this markup
<p><a href="#">LOAD VIDEO</a></p>
<video id="video" controls width="560">
<source id="webm" type="video/webm" />
<span>zoom-club.webm</span>
</video>
And this script
$(document).ready(function(){
$('a').on('click',function(){
var path = "../assets/" + $('span').text();
$('source').attr('src', path);
$('video#video').load();
$('video#video').play();
});
});
Why do I get this error?
Uncaught TypeError: undefined is not a function
This will actually work using tradition Javascript and getElementById, but for some reason the way I am referencing the video tag is broken. What gives?
Given this markup
<p><a href="#">LOAD VIDEO</a></p>
<video id="video" controls width="560">
<source id="webm" type="video/webm" />
<span>zoom-club.webm</span>
</video>
And this script
$(document).ready(function(){
$('a').on('click',function(){
var path = "../assets/" + $('span').text();
$('source').attr('src', path);
$('video#video').load();
$('video#video').play();
});
});
Why do I get this error?
Uncaught TypeError: undefined is not a function
This will actually work using tradition Javascript and getElementById, but for some reason the way I am referencing the video tag is broken. What gives?
Share Improve this question asked Aug 23, 2014 at 13:02 mmcglynnmmcglynn 7,67218 gold badges53 silver badges82 bronze badges 1- possible duplicate of Play/pause HTML 5 video using JQuery – Qantas 94 Heavy Commented Aug 23, 2014 at 13:07
1 Answer
Reset to default 3You get this error because
$('video#video')
gives you a jQuery object back. But it doesn't have a play()
method.
So you need to extract the DOM object from it:
$('video#video')[0]
Now on this you can invoke play()
:
$('video#video')[0].play();
Given this markup
<p><a href="#">LOAD VIDEO</a></p>
<video id="video" controls width="560">
<source id="webm" type="video/webm" />
<span>zoom-club.webm</span>
</video>
And this script
$(document).ready(function(){
$('a').on('click',function(){
var path = "../assets/" + $('span').text();
$('source').attr('src', path);
$('video#video').load();
$('video#video').play();
});
});
Why do I get this error?
Uncaught TypeError: undefined is not a function
This will actually work using tradition Javascript and getElementById, but for some reason the way I am referencing the video tag is broken. What gives?
Given this markup
<p><a href="#">LOAD VIDEO</a></p>
<video id="video" controls width="560">
<source id="webm" type="video/webm" />
<span>zoom-club.webm</span>
</video>
And this script
$(document).ready(function(){
$('a').on('click',function(){
var path = "../assets/" + $('span').text();
$('source').attr('src', path);
$('video#video').load();
$('video#video').play();
});
});
Why do I get this error?
Uncaught TypeError: undefined is not a function
This will actually work using tradition Javascript and getElementById, but for some reason the way I am referencing the video tag is broken. What gives?
Share Improve this question asked Aug 23, 2014 at 13:02 mmcglynnmmcglynn 7,67218 gold badges53 silver badges82 bronze badges 1- possible duplicate of Play/pause HTML 5 video using JQuery – Qantas 94 Heavy Commented Aug 23, 2014 at 13:07
1 Answer
Reset to default 3You get this error because
$('video#video')
gives you a jQuery object back. But it doesn't have a play()
method.
So you need to extract the DOM object from it:
$('video#video')[0]
Now on this you can invoke play()
:
$('video#video')[0].play();
本文标签: javascriptHow do I reference the HTML5 video element using jQueryStack Overflow
版权声明:本文标题:javascript - How do I reference the HTML5 video element using jQuery? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745563926a2156334.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论