i've been tried some code :
a.html :

<div class="content">
    <a href="howto_google_maps.asp">Google Maps</a><br>
    <a href="howto_css_animate_buttons.asp">Animated Buttons</a><br>
    <a href="howto_css_modals.asp">Modal Boxes</a><br>
    <a href="howto_js_animate.asp">Animations</a><br>
    <a href="howto_js_progressbar.asp">Progress Bars</a><br>
    <a href="howto_css_dropdown.asp">Hover Dropdowns</a><br>
    <a href="howto_js_dropdown.asp">Click Dropdowns</a><br>
    <a href="howto_css_table_responsive.asp">Responsive Tables</a><br>
</div>

b.html (1st trial), i got this from w3schools :

<html>
<head>
<script src="js/jquery-3.3.3.min.js"></script>
<script>
    function includeHTML() {
        var z, i, elmnt, file, xhttp;
        /*loop through a collection of all HTML elements:*/
        z = document.getElementsByTagName("*");
        for (i = 0; i < z.length; i++) {
            elmnt = z[i];
            /*search for elements with a certain atrribute:*/
            file = elmnt.getAttribute("w3-include-html");
            if (file) {
                /*make an HTTP request using the attribute value as the file name:*/
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4) {
                    if (this.status == 200) {elmnt.innerHTML = this.responseText;}
                    if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
                    /*remove the attribute, and call this function once more:*/
                    elmnt.removeAttribute("w3-include-html");
                    includeHTML();
                }
            }      
            xhttp.open("GET", file, true);
            xhttp.send();
            /*exit the function:*/
            return;
            }
        }
    };
</script>
</head>
<body>
    <p>Testing to call content from another html file</p>
    <div w3-include-html="a.html"></div>

    <script>
      includeHTML();
    </script>
</body>
</html>

b.html (2nd trial), while this i got from stackoverflow forum :

 <html>
    <head>
    <script src="js/jquery-3.3.3.min.js"></script>
    <script>
        <script> 
        $(function(){
            $("#includedContent").load("a.html"); 
        });
    </script>
    </script>
    </head>
    <body>

        <p>Testing to call content from another html file</p>
        <div id="includeContent"></div>

    </body>
    </html>

but still don't work. do i have a mistake or something ? helping me to solve this i would appreciate it.
thanks in advance brothers/sisters.

Dani AI

Generated

In 's snippets the problem is almost certainly a simple syntax/typo issue plus an environment restriction. The second b.html contains a nested <script> tag (invalid JavaScript) and an ID/selector mismatch — the loader calls #includedContent while the DIV is id="includeContent". Either one will stop the load from running. Also, both XMLHttpRequest and jQuery AJAX calls will fail when pages are opened over file:// in many browsers; the browser console or Network tab will show a failed request (404, status 0, or a protocol/CORS error) if that is the cause.

A concise, corrected jQuery pattern (different from the examples posted) — load only the inner .content and handle errors:

<!-- b.html (snippet) -->
<div id="includedContent"></div>

<script src="js/jquery.min.js"></script>
<script>
$(function(){
  // load only the .content element from a.html
  $("#includedContent").load("a.html .content", function(response, status, xhr){
    if (status === "error") {
      console.error("Load failed:", xhr && xhr.status, xhr && xhr.statusText);
    }
  });
});
</script>

A modern alternative using fetch and extracting .content:

<script>
(async function(){
  try {
    const r = await fetch('a.html');
    if (!r.ok) throw new Error(r.status + ' ' + r.statusText);
    const html = await r.text();
    const tmp = document.createElement('div');
    tmp.innerHTML = html;
    const part = tmp.querySelector('.content');
    document.getElementById('includedContent').innerHTML = part ? part.innerHTML : html;
  } catch (err) {
    console.error('Include failed:', err);
  }
})();
</script>

Quick troubleshooting checklist and notes:

  • Serve pages over HTTP (for example python -m http.server) rather than opening via file://.
  • Confirm the script path and file name for jQuery are correct and that the loader runs after jQuery is loaded.
  • Check DevTools Console and Network tab for 404/CORS/protocol errors and for exact status codes.
  • Relative links inside the included HTML will resolve against the main document; use absolute paths or adjust accordingly.
  • If the included fragment needs JS behavior, bind handlers after the load or use delegated event handlers.

Fixing the syntax/ID problems and serving the files via HTTP resolves this class of include issues in nearly all cases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.