|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
SitePoint Zealot
![]() ![]() Join Date: Dec 2008
Posts: 175
|
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>
Code:
$(document).ready(function(){
if ($('p img').length >0) {
$("p img").css({
padding: '0px'
});
}
});
HTML Code:
<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> Thanks, Lau |
|
|
|
|
|
#2 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Apr 2007
Posts: 241
|
Code:
$('p').each(function(){
if($(this).find('img').length != 0){
$(this).css('padding', '0px');
}
});
|
|
|
|
|
|
#3 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2008
Posts: 4,774
|
Could also
Code:
$("img").closest("p")
//or
$("img").parents("p")
|
|
|
|
|
|
#4 |
|
SitePoint Zealot
![]() ![]() Join Date: Dec 2008
Posts: 175
|
hey thank you guys! got it.
$("img").parent("p").css({ padding:'0px' }); Thanks! Lau :-) |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 18:12.









Hybrid Mode
