Reputation: 71
For example this wraps the content of the test.html into the .wrapper , but i want to add the content of the html next to an existing div without wrapping it contents.
$( "#button" ).click(function() {
$( ".wrapper" ).load( "test.html" );
});
Upvotes: 1
Views: 330
Reputation: 167182
You need to use .after
and cannot use .load()
for this:
$("#button").click(function() {
$.get("test.html", function (res) {
$("selector-for-existing-div").after(res);
});
});
Let's say I want to put this after the h1
here:
$(function () {
$("#button").click(function() {
$.get("https://api.github.com/", function (res) {
$("h1").after(res.current_user_url);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Welcome</h1>
<input id="button" value="Click Me!" type="button" />
Upvotes: 2