Jump to content

Truncate jquery


dpiearcy

Recommended Posts

Ok.  I have the jsonp working the way it should and I get the info back from a cross domain url.  I copied the truncate portion of this code but it doesn't seem to be working for me.  What's wrong with this code?  

 

I know it will be obvious but I'm new to javascript.  :-)  

<script type="text/javascript">
$(function(){
  var minimized_elements = $('p.minimize');
    minimized_elements.each(function(){    
    var t = $(this).text();        
    if(t.length < 100) return;
        
    $(this).html(
	t.slice(0,100)+'<span>... </span><a href="#" class="more">More</a>'+'<span style="display:none;">'+ t.slice(100,t.length)+' <a href="#" class="less">Less</a></span>'
	);
        }); 
    $('a.more', minimized_elements).click(function(event){
	event.preventDefault();
	$(this).hide().prev().hide();
	$(this).next().show();        
	});
    
    $('a.less', minimized_elements).click(function(event){
	event.preventDefault();
	$(this).parent().hide().prev().show().prev().show();    
	});
$.get("http://www.somedomain.com/app_ajax.php?callback=?", function(data, textStatus){
	$.each(data, function(index, user){
	var newDiv = '<div class="prayer_received">'
	var newName = '<div class="name"><h2>' + (user.name) + '</h2></div>';
	var newRequest = '<div class="prayer"><p class="minimize">' + (user.request) + '</p></div>';
	var newDate = '<div class="date"><p>Posted on' + (user.date) + '</p></div>';
	var newTimes = '<div class="times"><p>Prayed for' + (user.times) + ' times</p></div>';
	var newRule = '<div class="rule"><hr></div></div>';

	$("#request").append(newDiv + newName + newRequest + newDate + newTimes + newRule);
	});
},
       "json"
	);              
});
</script>
Link to comment
https://forums.phpfreaks.com/topic/278473-truncate-jquery/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.