Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. var isfirst = 1, lastelm;
  2. $("#divid").find("*").each(function() {
  3. var cur = $(this);
  4. if(parseInt(cur.css("margin-top")) > 0 && isfirst == 1) {
  5. cur.css("margin-top", 0);
  6. isfirst = 0;
  7. }
  8. if(parseInt(cur.css("margin-bottom")) > 0) {
  9. lastelm = cur;
  10. }
  11. });
  12. lastelm.css("margin-bottom", 0);
  13.  
  14. <html>
  15. <body>
  16. <p>
  17. <p>A<p>
  18. <p>B<p>
  19. <p style="margin: 10px;">C<p>
  20. <p style="margin: 10px;">C<p>
  21. <p>D<p>
  22. </p>
  23. <script>
  24. $(document).ready(function(){
  25. $('p').filter(function(){
  26. return this.style.margin != '';
  27. }).last().css('color','red');
  28.  
  29. });
  30.  
  31. </script>
  32. <body>
  33.  
  34. #my-element > *:first-child {
  35. margin-top: 0;
  36. }
  37.  
  38. #my-element > *:last-child {
  39. margin-bottom: 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement