JavaScript / jQuery Html etiketleri sıyırma olmadan daha fazla / az göster

0 Cevap

Ben readmore / daha az özelliği uygulamak istiyoruz. yani html içeriğine sahip olacak ve ben o içeriği ilk birkaç karakteri göstermek için gidiyorum ve bunun önünde bir okuma daha bağlantı olacak. Şu anda bu kodu kullanıyorum:

    var txtToHide= input.substring(length);
    var textToShow= input.substring(0, length);
    var html = textToShow+ '<span class="readmore">&nbsp;&hellip;&nbsp;</span>' 
+ ('<span class="readmore">' + txtToHide+ '</span>');
    html = html + '<a id="read-more" title="More" href="#">More</a>';

Above input is the input string and length is the length of string to be displayed initially. There is an issue with this code, suppose if I want to strip 20 characters from this string: "Hello <a href='#'>test</a> output", the html tags are coming between and it will mess up the page if strip it partially. What I want here is that if html tags are falling between the range it should cover the full tag i.e I need the output here to be "Hello <a href='#'>test</a>" . How can I do this

0 Cevap