我有一個前置標簽
<pre>This is the Pre Tag Example </pre>
我想使用 jquery 或 css 添加一個 before pre 標記,目前我撰寫的代碼附加了 pre 標記。
當前代碼:
pre:after {
content: '\f0c5';
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
margin-left:5px;
color:black;
}
它的顯示像之前:之后但那不是預期的..
預期結果
<img id="theImg" class="fa fa-files-o">
<pre>This is the Pre Tag Example </pre>
uj5u.com熱心網友回復:
您可以使用 jQuery 的.before()或.insertBefore( )在其他元素之前添加元素。
例如
$("<i>", {
id: "theImg",
class: "fa fa-files-o",
}).insertBefore("pre:first");
// This is just to show you the resulting markup
console.log("result:", $("div").html().trim());
/* Fake FontAwesome */
.fa.fa-files-o::before { content: "??"; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
<div>
<pre>This is the Pre Tag Example </pre>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/513433.html
標籤:jQuerycss