[英]How can i replace a tag with video tag
I want to replace <a href="123".......>text</a>
with <video src="123"..... />
How can i do this with jquery/javascript?我想用
<video src="123"..... />
替换<a href="123".......>text</a>
我如何使用 jquery/javascript 来做到这一点?
Like this:像这样:
$(document).ready(function(){
var $a = $("a");
$("<video/>").attr("src", $a.attr("href")).after($a);
$a.remove();
});
Hope this helps.希望这可以帮助。
Or I assume you want to replace the a tags after clicking?或者我假设您想在单击后替换 a 标签? NOTE: I replace the 'video' tag with div, just for making it easier for you to see the change.
注意:我用 div 替换了“video”标签,只是为了让您更容易看到更改。
$(document).ready(function(){
$('.toVideo').live('click', function(e){
$(this).replaceWith('<div src="' + $(this).attr('href') + '">new video</div>');
e.preventDefault();
})
})
Here is the example: http://jsfiddle.net/a9xHS/5/这是示例: http://jsfiddle.net/a9xHS/5/
Or if you want to replace all tags, maybe you can:或者,如果您想替换所有标签,也许您可以:
$(document).ready(function(){
$('.toVideo').each(function(){
$(this).replaceWith('<div src="' + $(this).attr('href') + '">' + $(this).attr('href') + '</div>');
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.