我正在写一个chrome扩展程序来更改某个朋友的某个网站的徽标。问题在于徽标是<svg>
标签。如何更改js中的HTML标签和内容?
不知道是否允许使用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>
如果只能使用JavaScript,则有一个replaceChild
功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句