Is there a way to change the CSS of a parent div only if the child is visible? And back again when not??? I've been racking my brains and I'm all Googled and jQuery documentationed out.
+5
A:
$(".childClass").each(function(){
if($(this).is(":visible"))
{
$(this).parent().css("some_attribute", "some_value");
}
else
{
$(this).parent().css("some_attribute", "default_value");
}
});
You can also use addClass/RemoveClass on the parent, but be careful if you remove a class that you're using as part of the selector to find the child element.
Chris Doggett
2009-08-20 14:23:33
+1
A:
if(($('#childId').css('display')!="none")&&($('#childId').css('visibility')!="hidden"){
$('#childId').parent().css('property',value);
}
Gregoire
2009-08-20 14:25:43
A:
This may not be quite as efficient as Chris Doggett's, but it's shorter... thought I'd throw it out there so you'd have the option:
$("childClass:visible").parent().css("some_attribute", "some_value");
$("childClass:hidden").parent().css("some_attribute", "default_value");
Max Schmeling
2009-08-20 14:25:57
A:
$(".childClass").each(function(){
var $this = $(this);
$this.is(":visible") ? $this.parent().css("some_attribute", "some_value")
: $this.parent().css("some_attribute", "some_value")
});
redsquare
2009-08-20 14:40:44
Thanks for your help guys, really appreciated!
2009-08-21 06:23:22