Skip to content

Instantly share code, notes, and snippets.

@felipefernandes
Last active December 11, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipefernandes/40c332b697ef82162fd127a851e60e85 to your computer and use it in GitHub Desktop.
Save felipefernandes/40c332b697ef82162fd127a851e60e85 to your computer and use it in GitHub Desktop.
Uma forma de fazer includes usando JS

Include usando Javascript

Pre-requisitos

Só funciona em um dominio, mesmo que seja http://localhost.

Passo a passo

  1. Crie um arquivo include.js.
$( document ).ready(function() {	
    //loads static html content
    $("[data-load]").each(function(){
            $(this).load($(this).data("load"), function(){
        });
    });    
});
  1. Carregue o arquivo criado no rodapé do arquivo onde vai receber includes.

  2. Coloque o código abaixo para fazer o include:

<nav class="nav-bar" data-load="inc/mainmenu.html"></nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment