Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2009, 05:28 PM   PM User | #1
lauthiamkok
Regular Coder

 
Join Date: Dec 2008
Posts: 117
Thanks: 14
Thanked 0 Times in 0 Posts
lauthiamkok is an unknown quantity at this point
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
lauthiamkok is offline   Reply With Quote
Old 11-08-2009, 09:35 AM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Doing something like this is certainly possible....

So does that code of yours work?
__________________
Fumigator is offline   Reply With Quote
Old 11-08-2009, 09:59 AM   PM User | #3
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Code:
$('p img').parents('p').css({ padding: '0px' });
Bill Posters is offline   Reply With Quote
Old 11-08-2009, 12:56 PM   PM User | #4
lauthiamkok
Regular Coder

 
Join Date: Dec 2008
Posts: 117
Thanks: 14
Thanked 0 Times in 0 Posts
lauthiamkok is an unknown quantity at this point
Quote:
Originally Posted by Bill Posters View Post
Code:
$('p img').parents('p').css({ padding: '0px' });
thank you. it works perfectly now!
lauthiamkok is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:36 PM.


Advertisement
Log in to turn off these ads.