Change the content of the element using load method in jquery

In this example first we create a text file( in my case txt.txt). Now we can load it in our example:

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").load('txt.txt');
  });
});
</script>
</head>
<body>

<div><h2>Example of change thye Text In JQuery</h2></div>
<button>Click Me To Change The Content</button>

</body>
</html>


Output:


1.png

After we click on the button:


2.png
Ebook Download
View all
Learn
View all