Include file In HTML by JavaScript or jquery dynamically

前端 未结 1 1609
既然无缘
既然无缘 2021-01-17 06:12

I tried the following code. But it doesn\'t work properly. Only one file add/ include repetitively. How can I solve this? **I want to create a custom tag \"\" which can INCL

1条回答
  •  离开以前
    2021-01-17 06:40

    is not a valid html element.

    You can use element with rel attribute set to "import" to load resources into document. At load event of element you can get the content of resource using link.import

    
    

       $(function() {
         $("body").append($("link[href='nav.html']")[0].import.body.innerHTML)
       })
    

       $("link[href='nav.html']").on("load", function() {
         $("body").append(this.import.body.innerHTML)
       })
    

    Alternatively, you can use .load()

       $("#element").load("nav.html");
    

    0 讨论(0)
提交回复
热议问题