Trying to learn Ajax - jQuery through simple code samples I have this two html files as: index.html and source.html.the inex.html is as:
enter code here
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('button').click(function(){
$.get('source.html', function(data) {
$('.result').html(data);
});
});
});
</script>
<title>Main Page</title>
</head>
<body>
<button>Load Page</button>
<div class="result"></div>
</body>
</html>
and the source.html as:
enter code here
<!DOCTYPE html>
<html>
<head>
<title>Source Page</title>
</head>
<body>
<div class="test1">Hello Ajax!</div>
<div class="test2"> Again Hello Ajax!</div>
<div class="test1">WoW Ajax!</div>
<p> The html() method sets or returns the content(innerHTML) of the selected... </p>
</body>
</html>
now my question is how I can grab specific elements instead of getting all elements in the index page? For example , how I can filter the request object to just get all div with class "test1" or only
from the page source.I also do not really understand what does "data" parameter means in
enter code here
$.get('source.html', function(data) {
$('.result').html(data);
can you please let me know what does it mean?
data from Console:
<!DOCTYPE html>
<html>
<head>
<title>Main Page</title>
</head>
<body>
<div class="test">Hello world!</div>
<div class="test1">Hello Ajax!</div>
<div class="test2"> Again Hello Ajax!</div>
<div class="test1">WoW Ajax!</div>
<p> The html() method sets or returns the content (innerHTML) of the selected elements.When this method is used to return content, it returns the content of the FIRST matched element. When this method is used to set content, it overwrites the content of ALL matched elements.</p>
</body>
</html>