Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <h2>Example example example example example</h2>
  2. <h2>Example</h2>
  3.  
  4. $(document).ready(function(){
  5. var dtl = $('.h2').text().length;
  6.  
  7. if(dtl>10){
  8. $('.h2').text().length = 10;
  9. $('.h2').text($('.h2').text()+"...");
  10. }
  11. });
  12.  
  13. $(document).ready(function(){
  14. var dtl = $("h2").text().length;
  15.  
  16. if(dtl>10){
  17. $('h2').text($('h2').text().substr(0,10)+"...");
  18. }
  19. });
  20.  
  21. $(document).ready(function(){
  22.  
  23. $("h2").each(function() {
  24. if($(this).text().length > 10) {
  25. $(this).text($(this).text().substr(0,10)+"...");
  26. }
  27. });
  28. });
  29.  
  30. $("h2").each(function() {
  31. var dtl = $(this).text().length;
  32. //rest of your code goes here
  33. if(dtl>10){
  34. var res = $(this).text();
  35. res = res.substring(0, 4); //apply your logic here what ever you want pass (0, 10)
  36. $(this).text(res +"...");
  37. }
  38. });
  39.  
  40. <h2>This tag contains more than 10 characters</h2>
  41.  
  42. $(document).ready(function () {
  43. var len = $("h2").text().length;
  44. var text = $("h2").text();
  45.  
  46. if (len > 10) {
  47. var stext = text.substring(0, 10);
  48. $("h2").text(stext).append("...");
  49. }
  50.  
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement