Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
Read More functionality code is not working as expected

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.

enter image description here

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'); 
    }
    
});
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Based on your video, I see that the hidden text was already shown. So first click at READ MORE button will do nothing and no fade in because the content was already shown (except text changed to LESS). jQuery fadeIn() does not do anything if the element was already shown and the same for fadeOut() for hidden element.

If you want the content hidden at first, update the div element with this <div class='fullsec' style='display: none;'> inside your PHP code. The Javascript code is fine.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda