0

how do I apply css to parent if his child have a certain class?

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"

1

2 Answers 2

1

Try :has selector:

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

how can I do it without approaching p tag? because it's sometimes a p and sometimes a div
@eyalhalperin you can do it like this: $(":has(>span.validationMessage)").css("border","1px dotted #090");
0

.parent()

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

also look at

.hasClass()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.