I wa开发者_JAVA百科nt to replace <a href="123" .......>text</a>
with <video src="123"..... />
How can i do this with jquery/javascript?
Or I assume you want to replace the a tags after clicking? NOTE: I replace the 'video' tag with div, just for making it easier for you to see the change.
$(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/
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>');
})
})
http://jsfiddle.net/A9R3L/1/
Like this:
$(document).ready(function(){
var $a = $("a");
$("<video/>").attr("src", $a.attr("href")).after($a);
$a.remove();
});
Hope this helps.
Check out jQuery's replaceAll()
method
精彩评论