Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jquery: how to find the children inside an element

    Hi,

    How can I find if each of the <p> tags contains <img> tag, then style the <p> tags which contain <img> inside them?

    I have pre-set all <p> will have this style,
    Code:
    <style>
    p { padding:0px 0px 20px 0px;}
    </style>
    The function to re-style the <p> which contains <img> inside them,
    Code:
    $(document).ready(function(){
    	
    	if ($('p img').length >0) {
    		$("p img").css({
    		padding: '0px'
    		});
    	}
    });
    The HTML,
    [HTML]<div id="content">
    <p><img src="img.jpg"/></p>

    <p>Lorem ipsum dolor sit amet</p>

    <p><img src="img.jpg"/></p>

    <p>Lorem ipsum dolor sit amet</p>
    </div>[/HTML]

    Is it possible?

    Thanks,
    Lau

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Doing something like this is certainly possible....

    So does that code of yours work?

  • #3
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Code:
    $('p img').parents('p').css({ padding: '0px' });

  • #4
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters View Post
    Code:
    $('p img').parents('p').css({ padding: '0px' });
    thank you. it works perfectly now!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •