Last active
November 24, 2022 04:49
-
-
Save mudassaralichouhan/c5fa318265bad85387cefe37b21985a2 to your computer and use it in GitHub Desktop.
let clonedMenu = menu.cloneNode(true)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<title>JavaScript cloneNode() Demo</title> | |
</head> | |
<body> | |
<ul id="menu"> | |
<li>Home</li> | |
<li>Services</li> | |
<li>About</li> | |
<li>Contact</li> | |
</ul> | |
<script> | |
let menu = document.querySelector('#menu'); | |
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((val, index) => { | |
let clonedMenu = menu.cloneNode(true); | |
clonedMenu.id = 'menu-mobile-' + index; | |
clonedMenu.querySelectorAll('li').forEach((el, index) => { | |
el.innerHTML = el.textContent + ' ' + index + ' ' + val; | |
}); | |
document.body.appendChild(clonedMenu); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment