Skip to content

Instantly share code, notes, and snippets.

@TannerRogalsky
Created July 24, 2011 18:26
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 TannerRogalsky/1102913 to your computer and use it in GitHub Desktop.
Save TannerRogalsky/1102913 to your computer and use it in GitHub Desktop.
Injecting only part of a remote page into the DOM via jQuery AJAX get request.
<html>
<head>
<script src="jquery-1.6.2.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
$.ajaxSetup ({
cache: false
});
$('a').click(function(){
$.get(
"index2.html",
function(responseText){
$("#result").html(responseText);
$("#remove").remove();
},
"html"
);
});
});
</script>
<div id="result"><a href="#">Click Me!</a></div>
</body>
</html>
<html>
<head>
</head>
<body>
Hello, World!
<div id="remove">Test.</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment