Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var divHeight = $('.myDiv').height();
- if (divHeight > 50) {
- $('.icon_collase').appendTo('.myDiv');
- }
- <style>
- .collasedDiv {
- max-height:50px;
- }
- </style>
- $(".icon_collase").click(function() {
- $('.icon_collase').toggleClass('icon_collase icon_expand');
- $('.myDiv').addClass('collasedDiv');
- }
- <div class="myDiv">
- // content here
- </div>
- <div class="myDiv">
- // another content here
- </div>
- var $YourDivs = $('.myDiv').filter(function(){ return $(this).height() > 50; });
- // since we're passing in a set, jquery will clone '.icon-collase' for you
- $('.icon_collase').appendTo($YourDivs);
- $(".icon_collase").click(function() {
- $(this).closest('.myDiv').toggleClass('icon_collase icon_expand')
- });
- $(".icon_collase").click(function(e) {
- $(e.target).toggleClass('icon_collase icon_expand');
- $(e.target).closest('.myDiv').addClass('collasedDiv');
- $(".myDiv").each(function(){
- var divHeight = $(this).height();
- if (divHeight > 50) {
- $(this).append('icon_collase');// you might want to edit this icon_collase should be a html element ?
- }
- });
- }
Add Comment
Please, Sign In to add comment