I'm trying to use jQuery to change paragraph text based upon the class of the div in which it resides.
I want each of the class names in the array to replace the p text within their respective divs. Right now I just get the last div's class name for the p text.
<div class="ph player">PHILIPPINES<p class="topic">Test topic</p></div>
<div class="sl player">SOLOMON ISLANDS<p class="topic">Test topic</p></div>
<div class="fi player">FIJI<p class="topic">Test topic</p></div>
<div class="sm player">SAMOA<p class="topic">Test topic</p></div>
<script>
var divArr = ["ph", "sl", "fi", "sm"];
$.each(divArr, function(index, value) {
$(".topic").text(this);
});
</script>
Thanks for looking. Total beginner here.