I am just starting to learn js and need your help.
I have following code:
<html>
<head>
<title>test</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('.test1').(function(){
this.each(function () {
var a = $(this);
alert(a);
});
});
});
</script>
</head>
<body>
<pre class="test1">
blabla1
blabla2
blabla3
</pre>
</body>
</html>
With this code I wanted to find out how “each” will split the content of the pre-tag. Firebug returns following error message:
XML filter is applied to non-XML value
The error is caused by this command:
$('.test1').(function(){...
What am I doing wrong?
Many thanks in advance!
If you really want to see how
.eachworks in your example, change code to:However, like @James_Johnson said earlier, the code in
.eachfunction will only execute once, so you are likely to seein your alert message
To make
.eachiterate, you have to do sth like