简体   繁体   中英

how can I add links to my nav bar in javascript?

I am pretty new to javascript. I am trying to add a link (Section 1) to my nav bar and I am not sure why I still can't see it in the preview.

var link = document.createElement('a');
link.classList.add('menu__link');
link.href = '#section1';
link.textContent = 'Section 1';
document.getElementById('navbar__list').appendChild(link);

in the second line of your code 'l' letter of 'link' word is missing.

 var link = document.createElement('a'); link.classList.add('menu__link'); link.href = '#section1'; link.textContent = 'Section 1'; document.getElementById('navbar__list').appendChild(link);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM