I am using ACF repeater to create user profiles that have a "read more/read less" function that shows and hides text. The issue I'm facing is when I press the "read more" button for the 3rd profile down, it opens the first profile. How do I make this functionality dynamic so it only opens/closes the profile being clicked?
<div class="container" style="margin-top: 60px;">
<?php if(have_rows('profile')): ?>
<?php while(have_rows('profile')): the_row(); ?>
<div class="row">
<div class="col-md-3">
<div class="people-img" style="background-image: url('<?php echo the_sub_field("profile_img"); ?>')"></div>
</div>
<div class="col-md-9">
<h4 class="profile-name">
<?php the_sub_field('name'); ?>
</h4>
<p class="profile-job-title semi-bold">
<?php the_sub_field('info'); ?>
</p>
<p><?php the_sub_field('profile_blurb'); ?><span id="dots">...</span><span id="more"><?php the_sub_field('profile_read_all'); ?></span></p>
<div class="about-readmore" onclick="myFunction()" id="myBtn">Read more</div>
<div class="readmore-border"></div>
</div>
</div><!-- end row -->
<div class="profile-border"></div>
<?php
endwhile;
else:
endif;
?>
<script>
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
</script>
#more {display: none;}