Answers for "how to add a child to a parent element js"

1

how to add a child to a parent element js

function createMenuItem(name) {
    let li = document.createElement('li');
    li.textContent = name;
    return li;
}
// get the ul#menu
const menu = document.querySelector('#menu');
// add menu item
menu.appendChild(createMenuItem('Home'));
menu.appendChild(createMenuItem('Services'));
menu.appendChild(createMenuItem('About Us'));
Posted by: Guest on October-17-2020

Code answers related to "how to add a child to a parent element js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language