Guest User

Untitled

a guest
Jul 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var divHeight = $('.myDiv').height();
  2.  
  3. if (divHeight > 50) {
  4. $('.icon_collase').appendTo('.myDiv');
  5. }
  6.  
  7. <style>
  8. .collasedDiv {
  9. max-height:50px;
  10. }
  11. </style>
  12.  
  13. $(".icon_collase").click(function() {
  14. $('.icon_collase').toggleClass('icon_collase icon_expand');
  15. $('.myDiv').addClass('collasedDiv');
  16. }
  17.  
  18. <div class="myDiv">
  19. // content here
  20. </div>
  21.  
  22. <div class="myDiv">
  23. // another content here
  24. </div>
  25.  
  26. var $YourDivs = $('.myDiv').filter(function(){ return $(this).height() > 50; });
  27.  
  28. // since we're passing in a set, jquery will clone '.icon-collase' for you
  29. $('.icon_collase').appendTo($YourDivs);
  30.  
  31. $(".icon_collase").click(function() {
  32. $(this).closest('.myDiv').toggleClass('icon_collase icon_expand')
  33. });
  34.  
  35. $(".icon_collase").click(function(e) {
  36. $(e.target).toggleClass('icon_collase icon_expand');
  37. $(e.target).closest('.myDiv').addClass('collasedDiv');
  38.  
  39. $(".myDiv").each(function(){
  40. var divHeight = $(this).height();
  41.  
  42. if (divHeight > 50) {
  43. $(this).append('icon_collase');// you might want to edit this icon_collase should be a html element ?
  44. }
  45. });
  46.  
  47. }
Add Comment
Please, Sign In to add comment