The information I need is in a meta tag. How can I access the "content"
data of the meta tag when property="video"
?
HTML:
JavaScript
x
2
1
<meta property="video" content="http://video.com/video33353.mp4" />
2
Advertisement
Answer
You can use this:
JavaScript
1
14
14
1
function getMeta(metaName) {
2
const metas = document.getElementsByTagName('meta');
3
4
for (let i = 0; i < metas.length; i++) {
5
if (metas[i].getAttribute('name') === metaName) {
6
return metas[i].getAttribute('content');
7
}
8
}
9
10
return '';
11
}
12
13
console.log(getMeta('video'));
14