Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello,

I'm trying to open a nav bar below on every page I have.

HTML
<nav>
    <ul id="slide-out" class="side-nav fixed">
        <li><a href="index.html">index</a></li>
        <li><a href="about.html">about</a></li>
        <li><a href="news.html">news</a></li>
        <li><a href="hybrids.html">hybrids</a></li>
        <li><a href="puppies.html">puppies</a></li>
    </ul>
    <a href="#" data-activates="slide-out" class="button-collapse"></a>
</nav>


For that I'm calling the html file with Jquery to load into the header tag:

JavaScript
$().ready(function () {
   $("header").load("master.html");
});


One thing I noticed is that the "slide out" effect is not working. After researching, I've found out that jQuery's load method "strips away" the script from html (please correct me if I'm wrong). Some suggested loading the script again, but it didn't work. I think it has something to do with the data-activates property/attribute, but I can't find much information about it.

Has anyone had this issue? how did you solve it?
Posted
Updated 21-Jul-15 5:07am
v2

1 solution

After a lot of trials and tests and getting my peers involved into the issue. We noticed that the html file was loading only after the scripts that assigned events to the tags.

To fix this I changed the call to:

$("header").load("master.html", function () { /*code to execute*/ });


That allowed for the file to be loaded before any work to be done on it.
For more information: http://api.jquery.com/load/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900