我目前正在学习Java脚本,并测试如何调用和更新元素的子元素.我能够更新中间的子元素,现在我想使用中间的子元素更新第一个子元素,我不确定我做错了什么.
var div = document.getElementsByTagName("div")[0];
var midp = div.children[1];
var midPText = (midp.innerHTML = "This is the middle child");
var firstp = midp.previousSibling;
var firstPText = firstp.innerHTML = "This is the first child";
<div>
<p style="margin-top:2rem; background-color:#ccff33; padding:2rem; color:black;"></p>
<p style="margin-top:2rem; background-color:#99cc00; padding:2rem; color:white;"></p>
<p style="margin-top:2rem; background-color:#394d00; padding:2rem; color:white;"></p>
</div>