admin管理员组文章数量:1292298
I am trying to create the HTML markup using jquery:
<div class="icon"></div>
If the youtube video exists on the page then create the above markup:
if ($('div.container iframe').length) {
alert('frame exists');
$('<div class="icon"></div>');
}
However its not create the markup. I want the user to paste a youtube video then my Jquery should create the icon automatically for them. Please look at my implementation:
var $video = $('div.container iframe'); //location of video
var $productImage = $('.product-image'); //location of main prod img
var $icon = $('.icon'); //location of icon
//check if video exists
if ($('div.container iframe').length) {
alert('frame exists');
$('<div class="icon"></div>');
}
$('.product-image').append($video); //append the video to the main prod img
$icon.on('click', function() { //click
$video.toggle(); //toggle the video based on click
});
JSFIDDLE: / SOLUTION: /
I am trying to create the HTML markup using jquery:
<div class="icon"></div>
If the youtube video exists on the page then create the above markup:
if ($('div.container iframe').length) {
alert('frame exists');
$('<div class="icon"></div>');
}
However its not create the markup. I want the user to paste a youtube video then my Jquery should create the icon automatically for them. Please look at my implementation:
var $video = $('div.container iframe'); //location of video
var $productImage = $('.product-image'); //location of main prod img
var $icon = $('.icon'); //location of icon
//check if video exists
if ($('div.container iframe').length) {
alert('frame exists');
$('<div class="icon"></div>');
}
$('.product-image').append($video); //append the video to the main prod img
$icon.on('click', function() { //click
$video.toggle(); //toggle the video based on click
});
JSFIDDLE: http://jsfiddle/t7qMF/7/ SOLUTION: http://jsfiddle/t7qMF/13/
Share Improve this question edited Jul 13, 2012 at 10:13 SOLDIER-OF-FORTUNE asked Jul 13, 2012 at 10:00 SOLDIER-OF-FORTUNESOLDIER-OF-FORTUNE 1,6545 gold badges39 silver badges68 bronze badges 1- div.icon has its own css, so you should see an icon appear on the page. – SOLDIER-OF-FORTUNE Commented Jul 13, 2012 at 10:03
2 Answers
Reset to default 8First check if iframe exists or not and if exists then append
icon div -
if ($('div.container iframe').length > 0) {
alert('frame exists');
$('.container').append('<div class="icon">Icon</div>');
}
Updated Fiddle - http://jsfiddle/t7qMF/11/
$('<div class="icon"></div>');
creates the markup but doesn't put it any where. Append that to something and it should work.
本文标签: javascriptchecking if an iframe exists and then creating HTML markup using jqueryStack Overflow
版权声明:本文标题:javascript - checking if an iframe exists and then creating HTML markup using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741549347a2384784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论