Hello i want to put a shorten text-SeeMORE function inside another function
$(function() {
var showTotalChar = 200, showChar = "Show (+)", hideChar = "Hide (-)";
$('.show').each(function() {
var content = $(this).text();
if (content.length > showTotalChar) {
var con = content.substr(0, showTotalChar);
var hcon = content.substr(showTotalChar, content.length - showTotalChar);
var txt= con + '<span class="dots">...</span><span class="morectnt"><span>' + hcon + '</span> <a href="" class="showmoretxt">' + showChar + '</a></span>';
$(this).html(txt); } });
$(".showmoretxt").click(function() {
if ($(this).hasClass("sample")) {
$(this).removeClass("sample");
$(this).text(showChar);
}
else {
$(this).addClass("sample");
$(this).text(hideChar);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
when i put it after the line that returns multiple values $.each(data, function(i,data){
it works OK as a function but returns multiple class="dots"
and multiples Show (+) and i am guessing its because i put it after the each function. I tried to put it before $.each(data, function(i,data){
but the shorten text function doesnt work then. Also i tried to put it in another JS file still tha same. Any guess? Thanks