我一直在苦苦尋找一個jQuery的替代方案,如不完全一樣:jQuery的替代等於「firstChild.nodeValue」
document.getElementById("element").firstChild.nodeValue = value;
下面是相關的HTML結構:
<div id="clock">
<div id="day">
</div>
<div id="date">
</div>
</div>
對於「日」和「日期」我可以只使用$("#day").text(day)
和$("#date").text(date)
,但只要我使用$("#clock").text(clock)
作爲「時鐘」,「日」和「日期」消失,只顯示「時鐘」元素。
當然,「clock」是其他兩個元素的父元素,所以如果我使用jQuery代碼,它可能會'覆蓋'子元素。奇怪的是,使用僞元素如:first-child
或:first
沒有幫助。
很高興聽到解決方案!謝謝。
我看到..使用某種形式的「前」功能的想法完全忘在腦後。我測試了它,它工作。非常感謝! – Daan