简体   繁体   English

如果孩子有某堂课,给父母css

[英]give css to parent if child has certain class

how do I apply css to parent if his child have a certain class? 如果他的孩子有某个班级,我如何将CSS应用于父母?

for example: 例如:

<p>
     <span class="validationMessage">Last Name is required field</span>
</p>

I want to give the p tag css base on that the his child element has class called "validationMessage" 我想基于他的子元素具有名为“ validationMessage”的类来给予c标签css

Try :has selector: 尝试:has选择器:

 $("p:has(span.validationMessage)").css(yourPCss);

Have a look: http://jsfiddle.net/jdfcr/ 看看: http : //jsfiddle.net/jdfcr/

.parent() .parent()

$('span.validationMessage').parent().css(style);

also look at 也看

.hasClass() .hasClass()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery-如果子元素具有某些CSS类,如何将CSS添加到父元素 - jQuery - How to add css to a parent element if child element has certain css class 当child具有某个类时,jQuery toggleClass为父类 - jQuery toggleClass to parent class when child has a certain class jQuery:如果孩子有类,则将class / css添加到父类 - jQuery: if child has class, add class/css to parent 如果父级具有特定值,则希望将CSS类添加到子级 - Looking to add CSS class to child if a parent has specific value 如果孩子有一个活跃的班级,那么也给父母一个活跃的班级-Vanilla JS - If a child has a class of active then give parent an active class too - Vanilla JS javascript:仅在父元素处于活动状态且子元素具有特定类的情况下,才如何向子元素添加属性? - javascript: how to add an attribute to a child element ONLY if a parent element is active AND child element has a certain class? 如果没有带类的子元素,则给父类 - Give parent class if there is no child elements with classes 选择子级的父级(如果有) - Selecting the parent of a child if it has a class 如果任何子元素具有某个类,则将类添加到父div,否则将其删除(jQuery或Javascript) - Add class to parent div if any of the child elements has a certain class, remove if not (jQuery or Javascript) 如果父级具有子类,则使用CSS或Jquery隐藏母体div secondchild类 - if parent has child class then hide mother div secondchild class with CSS or Jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM