Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var isfirst = 1, lastelm;
- $("#divid").find("*").each(function() {
- var cur = $(this);
- if(parseInt(cur.css("margin-top")) > 0 && isfirst == 1) {
- cur.css("margin-top", 0);
- isfirst = 0;
- }
- if(parseInt(cur.css("margin-bottom")) > 0) {
- lastelm = cur;
- }
- });
- lastelm.css("margin-bottom", 0);
- <html>
- <body>
- <p>
- <p>A<p>
- <p>B<p>
- <p style="margin: 10px;">C<p>
- <p style="margin: 10px;">C<p>
- <p>D<p>
- </p>
- <script>
- $(document).ready(function(){
- $('p').filter(function(){
- return this.style.margin != '';
- }).last().css('color','red');
- });
- </script>
- <body>
- #my-element > *:first-child {
- margin-top: 0;
- }
- #my-element > *:last-child {
- margin-bottom: 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement