Reputation: 52820
<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$("div.block").each(index){
this.text('Fill this writing of divs with the classname "block"')}
</script>
<body>
<div>Not here</div>
<div class='block'>replace me -- not working, why?</div>
<div>Not here</div>
<div class='block'>replace me -- not working, why?</div>
</body>
</html>
Upvotes: 0
Views: 4036
Reputation: 83358
You don't need to use each - you can just call the text method on your entire selection:
$("div.block").text('Fill this writing of divs with the classname "block"');
Incidentally, your problem above was that you were using each incorrectly
$("div.block").each(function(index, el){
$(el).text('Fill this writing of divs with the classname "block"');
});
Upvotes: 4