我只接受原始 js 答案,jquery 將被否決。
我有以下字串,讓我們稱之為MyHtmlAbove:
<span class="fc-title-wrap"><span class="fc-title fc-sticky">Some Sample Content here</span></span>
我知道我可以做到:
el = document.createElement('div');
el.innerHTML = myHtmlAbove;
我現在不知道該怎么做是:
fc-title在內容(前置)和圖示標記之前找到類和:<i class='font-awesome-here'></i>
我不確定我是否可以只使用常規的 raw:
el.findByClassName('fc-title').prepend('<i class='font-awesome-here'></i> ')
// Result should be:
<span class="fc-title-wrap"><span class="fc-title fc-sticky"><i class='font-awesome-here'></i> Some Sample Content here</span></span>
有人能指出我正確的方向嗎,我覺得我很接近。
因為我已經創建了一個臨時元素來進行這種操作,所以我還想清理它,這樣它就不會出現在不應該出現的 dom 中。
想法?
uj5u.com熱心網友回復:
document.getElementsByClassName('fc-title')[0].prepend('<i ></i> ')
// Result should be:
// <span ><span ><i class='font-awesome-her
<span class="fc-title-wrap"><span class="fc-title fc-sticky">Some Sample Content here</span></span>
uj5u.com熱心網友回復:
document.getElementsByClassName('fc-title')[0].prepend('<i ></i> ')
uj5u.com熱心網友回復:
原始 Js() 版本:
const fcT = document.querySelector(".fc-title");
const t = fcT.innerText
const icon = "<i class='font-awesome-here'></i>"
fcT.innerHTML = icon " " t;
console.log(document.querySelector(".fc-title"));
<span class="fc-title-wrap"><span class="fc-title fc-sticky">Some Sample Content here</span></span>
<i class='font-awesome-here'></i> Some Sample Content here</span>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482955.html
標籤:javascript
上一篇:ToDictionary中的KeyValuePair解構
下一篇:如何重新啟用鏈接懸停效果
