I’m learning JQuery. I’m a new Jquery Student as it is seen.
This is my html page:
<html>
<head>
<title>Jquery 1</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$("document").ready(function(){
var num = 0;
$("p").each(function(){
var data = data + $(this:eq(num)).html();
num =+1;
});
alert(data);
});
</script>
</head>
<body>
<p>
Deneme
</p>
<p>
Deneme2
</p>
</body>
</html>
I want to alert all p elements’ text. This code not working..
How can i do?
Change the code to this:
Inside the
.each()handler function, thethisvalue is the current DOM element in the iteration. Also, the.each()handler has two parameters on it that can also be used.indexis where you are in the iteration (from 0 to length-1) andelementis the current DOM element (same value asthis).You can read more about
.each()here.