[英]How Do I Change an <svg> Tag To An <img> Tag with js?
I'm writing a chrome extension to change a certain website's logo for a friend. 我正在写一个chrome扩展程序来更改某个朋友的某个网站的徽标。 The problem is that the logo is an
<svg>
tag. 问题在于徽标是
<svg>
标记。 How do I change the HTML tag and content in js? 如何更改js中的HTML标签和内容?
Not sure if you are allowed to use jQuery, but you could use replaceWith()
; 不知道是否允许使用jQuery,但是可以使用
replaceWith()
;
$(document).ready(function(e) { $('svg').replaceWith('<img src="http://images.all-free-download.com/images/graphiclarge/smiley_10_55841.jpg" alt="smiley!"/>'); });
svg { width: 200px; height:200px; } img { width: 200px; height: 200px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> <path d="M30,1h40l29,29v40l-29,29h-40l-29-29v-40z" stroke="#000" fill="none"/> <path d="M31,3h38l28,28v38l-28,28h-38l-28-28v-38z" fill="#a23"/> <text x="50" y="68" font-size="48" fill="#FFF" text-anchor="middle"><![CDATA[410]]></text> </svg> </div>
If you can only use JavaScript, there is a replaceChild
function. 如果只能使用JavaScript,则存在
replaceChild
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.