Jump to content

Truncate jquery


dpiearcy
Go to solution Solved by 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
Share on other sites

  • Solution

Never mind.  (seems I always do this...ask a question then look at my code after posting and figure out what I did wrong).

 

I see I needed to wrap that truncate part in my loop.  After doing that it works as it should.  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.