附加到 ul 和 li 元素以使它们出现在 DOM 中
您好,我尝试附加 li 和 a 以使它们出现在 DOM 中 我尝试复制文本内容,但我不知道如何使 li 和 a 出现在新的重复列表中。 第二个菜单应该出现在“smallNavArea”中
<nav>
<ul id="primaryNavigation">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="location.html">Menu</a></li>
</ul>
</nav>
<nav id="smallNavArea"></nav>
function duplicateMenu() {
let Menu = document.querySelectorAll('ul#primaryNavigation li a')
Menu.forEach(menuList => {
let Li_Element = document.createElement('li')
let newLink_Element = document.createElement('a')
newLink_Element .setAttribute('href', menuList.getAttribute('href'))
let MenuText = document.getElementById('primaryNavigation').textContent
})
}
duplicateMenu()
Hi I tried to append the li and a to make them appear in the DOM
I tried to copy the text content but I don't know how to make the li and a appear in the new duplicated list.
The second menu should be appear in the "smallNavArea"
<nav>
<ul id="primaryNavigation">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="location.html">Menu</a></li>
</ul>
</nav>
<nav id="smallNavArea"></nav>
function duplicateMenu() {
let Menu = document.querySelectorAll('ul#primaryNavigation li a')
Menu.forEach(menuList => {
let Li_Element = document.createElement('li')
let newLink_Element = document.createElement('a')
newLink_Element .setAttribute('href', menuList.getAttribute('href'))
let MenuText = document.getElementById('primaryNavigation').textContent
})
}
duplicateMenu()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在目标 DIV 中创建
UL
。然后,您需要将新链接附加到新 LI,并将新 LI 附加到新 UL。You need to create the
UL
in the destination DIV. Then you need to append the new link to the new LI, and append the new LI to the new UL.