I have a problem with the "read more" functionality I have implemented into my website. The code is working fine but only after two times of pressing the read more button created with the code. This code works when it detects the Wordpress read more tag on the text field in the backend and splits the text into two parts.
I'll paste a video of the problem here: https://vimeo.com/732701370
You can see also the problem in a page of my website like this one: https://mallorca-select.com/properties-for-sale/villa-project-in-ibiza/
I think that the code is working fine but there is only something that at first it makes the read more to not fold. If anyone can point me in the right direction would be awesome. Thank you
PHP CODE:
<?php
if(get_field('property_description')){
$highlights = get_field('property_description');
if(strpos($highlights, '<!--more-->') !== false) {
$start = strstr($highlights, '<!--more-->', true);
$end = strstr($highlights, '<!--more-->');
echo "<div class='exsec'>".$start."</div>";
echo "<div class='fullsec'>".$end."</div><div class='btnRM'><a href=''>READ MORE</a></div>";
} else {
echo $highlights;
}
}?>
JAVASCRIPT CODE:
jQuery('.btnRM a').click(function(e){
e.preventDefault();
if(jQuery(this).text()=="READ MORE"){
jQuery(this).parent().prev('.fullsec').fadeIn();
jQuery(this).text('LESS');
} else {
jQuery(this).parent().prev('.fullsec').fadeOut();
jQuery(this).text('READ MORE');
}
});
