jQuery function to add dots when text its too long [duplicate]
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
I have a code in jQuery, that adds dots when text its too long. It works but only for first span. When I have few spans with different text its not working. It works only when the text its the same. How to fix this? I want to work it for all spans when I add this id. When text is for example above 250 characters I want only display 250 characters and after that I want “…”
if ($(“.myspan”).html().length > 247) {
short_text = $(“.myspan”).html().substr(0, 247);
$(“.myspan”).html(short_text + “…”);
}
this is example span:
<span id=”myspan” class=”text myspan”>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto
sapiente ipsam veniam, accusamus eius fugiat molestiae totam dolorem sint adipisci amet incidunt
quam? Error delectus temporibus deleniti blanditiis aliquid ipsa.Lorem Lorem ipsum dolor sit
amet consectetur adipisicing elit. Perspiciatis maiores quae incidunt sit dicta quia amet
officiis voluptatibus nam hic placeat earum, minus consequatur eum temporibus, impedit maxime
dolorem voluptatem?
</span>
أضف إجابة