...

View Full Version : jquery: how to find the children inside an element



lauthiamkok
11-07-2009, 06:28 PM
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,

<style>
p { padding:0px 0px 20px 0px;}
</style>

The function to re-style the <p> which contains <img> inside them,

$(document).ready(function(){

if ($('p img').length >0) {
$("p img").css({
padding: '0px'
});
}
});

The 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>

Is it possible?

Thanks,
Lau

Fumigator
11-08-2009, 10:35 AM
Doing something like this is certainly possible....

So does that code of yours work?

Bill Posters
11-08-2009, 10:59 AM
$('p img').parents('p').css({ padding: '0px' });

lauthiamkok
11-08-2009, 01:56 PM
$('p img').parents('p').css({ padding: '0px' });

thank you. it works perfectly now! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum