So, I'm using jQuery to build a common menu in various HTML documents (page1.html, page2.html, page3.html).
Here is my code so far:
HTML Snippet:
<body>
<div class="menu">
</div>
</body>
JavaScript File:
var menucontent;
menucontent = "<ul>"+
"<li title="+"Page 1"+">"+"<a href="+"Page1.html"+">"+"Page 1"+"</a></li>"+
"<li title="+"Page 2"+">"+"<a href="+"Page2.html"+">"+"Page 2"+"</a></li>"+
"<li title="+"Page 3"+">"+"<a href="+"Page3.html"+">"+"Page 3"+"</a></li>"+
"</ul>";
$( ".menu" ).html(
menucontent
);
This all works fine, but its a pain in the ... to keep adding the "+" bits.
What I want to know is - can I have a separate html file with the below code in, that can be called into the JavaScript menucontent variable?
For your examples call the below menu.html...
<ul>
<li title="Page 1"><a href=Page1.html>Page 1</a></li>
<li title="Page 2"><a href=Page2.html>Page 2</a></li>
<li title="Page 3"><a href=Page3.html>Page 3</a></li>
</ul>
...or is there a better way to do this?