<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>
<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’)}
Share
You don’t need to use each – you can just call the text method on your entire selection:
Incidentally, your problem above was that you were using each incorrectly