Search the Community
Showing results for tags 'truncate'.
-
I have some data that I am displaying: var formatted_marker_data = "<div class=\"map_header\">" + data.formatted_address + "</div> The data.formatted_address is some MySQL data which is formatted like this: 123 Main Street, San Francisco, CA A few of the entries have the lat/lon added to the address: 123 Main Street, San Francisco, CA | 37.7917618,-122.3943405 I do not want to display anything after the | Is there a way to truncate all data after the | ? The only problem I see with that is that it WILL show the |, however I suppose since they are all CA addresses, I could truncate everything after the CA. Then again, if there is an address with a CA in it, then I'm screwed. Any ideas?
-
Ok. Have it truncating the way I want. Problem is now when I click "More" I get Less Less Less Less Less Less then the final Less is a link. The others are not. This is in the loop I get back from my PHP file using JSONP. I've looked at it 6 ways to Sunday but can't seem to figure out how to make less less's :-) Odd that only the last one is a link the rest are just text. $.each(data, function(index, user){ var minimized_elements = $('p.minimize'); minimized_elements.each(function(){ var t = $(this).text(); if(t.length < 90) return; $(this).html( t.slice(0,90)+'<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(); });
-
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>