![](/img/trans.png)
[英]Get all the content within <style> tag in a html file using jquery
[英]Modify html content using JQuery by style tag
我正在尝试基于样式标签编辑html内容
这是html的部分:
<!DOCTYPE html>
<html>
<body>
<span style="color:restest">Testing</span>
<br>
<span style="color:restest">Testing Again</span>
</body>
</html>
我想使用style =“ color:restest”修改span的所有实例,并将html标签添加到内容中。
它们应变为:
<a href="example.com/testing">Testing</a>
<a href="example.com/testing_again">Testing_Again</a>
最简单的方法是使用jQuery#replaceWith
:
$('span[style="color:restest"]').each((i,e) => { $(e).replaceWith(`<a href="example.com/${e.innerHTML}">${e.innerHTML}</a>`); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span style="color:restest">Testing</span> <span style="color:restest">Testing Again</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.