stackov
stackov

Reputation: 71

Jquery .load() html content without wrapping it to a div

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

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

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

Related Questions