Skip to content

Instantly share code, notes, and snippets.

@IanCal
Created August 31, 2013 13:47
Show Gist options
  • Save IanCal/6398286 to your computer and use it in GitHub Desktop.
Save IanCal/6398286 to your computer and use it in GitHub Desktop.
A simple inclusion approach
<!doctype html>
<head>
</head>
<body>
<section name="anchor1">
I am the INCLUDED THING
<section name="anchorsub">
I am a teeny tiny inclusion
</section>
</section>
</body>
</html>
<!doctype html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<section>
I am a main section
<section>
I am a subsection, with external links
<div><a href="includethis.html#anchor1" load="external">link 1</a></div>
<div><a href="includethis.html#anchorsub" load="external">link 2</a></div>
</section>
</section>
<script>
$("[load*='external']").each(function(i, _elem) {
var elem = $(_elem);
var linkurl = elem.attr("href").split("#");
var loc = linkurl[0];
var anchor = linkurl[1];
var url = loc + " [name*='" + anchor + "']";
elem.parent().load(url);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment