javascript noob… document write

前端 未结 5 1937
既然无缘
既然无缘 2021-01-22 10:55

I\'m trying to use Javascript to load more links in my nav bar.

This is what I tried; I just wanted one link in my nav to load more beneath it.



        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 11:32

    You can use innerHTML, or if you want to something more complex you could append a new element, for example:

    HTML

    collections
    

    Javascript

    function show() {
    var hidden= document.getElementById("hidden"),
        newElem = document.createElement("div");
    
    newElem.innerHTML = "
    collection 1
    collection 2
    etc...
    "; newElem.style.color = "red"; hidden.appendChild(newElem); }

提交回复
热议问题