On the news site there is always a brief description of one sentence, at the end of which we agreed not to put an end. But the editors sometimes forget and put. It is necessary by means of javascript or jquery to check and delete the point, if set.

Layout

<div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° с Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ.</p> </div> ... <div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° Π±Π΅Π· Ρ‚ΠΎΡ‡ΠΊΠΈ</p> </div> 

    2 answers 2

     $(".news_excerpt p").each(function(){ var text = $(this).text(); if (text.length && text[text.length - 1] == ".") { text = text.substr(0, text.length - 1); $(this).text(text); } }); 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° с Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ.</p> </div> ... <div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° Π±Π΅Π· Ρ‚ΠΎΡ‡ΠΊΠΈ</p> </div> 

      In order to remove the dot, if set, you can use regular expressions. For example:

       $(".news_excerpt p").each(function(){ var text = $(this).text().replace(/\.$/, ''); $(this).text(text); }); 
       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° с Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ.</p> </div> ... <div class="news_excerpt"> <p>Π’Ρ‹Π΄Π΅Ρ€ΠΆΠΊΠ° Π±Π΅Π· Ρ‚ΠΎΡ‡ΠΊΠΈ</p> </div> 

      • 2
        .each not needed, text can take a function : $(".news_excerpt p").text((i,oldText)=>oldText.replace(/\.$/, '')) - Grundy