How do I append HTML from a document loaded with AJAX?

前端 未结 6 1505
闹比i
闹比i 2021-01-13 19:13

I am trying to append the contents of a .html file to the body of my main page. Basically, I am trying to make a reusable chunk of html that I can load into any page with a

6条回答
  •  旧时难觅i
    2021-01-13 19:53

    Interestingly there is an upcoming W3C draft for HTML imports https://www.w3.org/TR/html-imports/

    Until then we can append the required markup to the DOM using Javascript.

    JQuery approach

    $(document).ready(function(){
        $( "body" ).load( "navbar.html" );
    });
    

提交回复
热议问题