ajax code to load page into div code example

Example 1: ajax load spesific element from another page

$.ajax({
   url:href,
   type:'GET',
   success: function(data){
       $('#container').html($(data).find('#content').html());
   }
});

Example 2: jQuery - AJAX load() Method

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").load("demo_test.txt");
  });
});
</script>
</head>
<body>

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

</body>
</html>

Example 3: ajax load spesific element from another page

$('#container').load('ajax/test.html #content');

Tags:

Html Example