Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:07:58+00:00 2026-06-04T06:07:58+00:00

How do I apply a style to the parent of an element if it

  • 0

How do I apply a style to the parent of an element if it has a specific property? Here’s the example I’m working with…

<div>
    <div class="inner"></div>
    <div class="inner"></div>
    <div class="inner"></div>
</div>
<div>
    <div class="inner active"></div>
    <div class="inner"></div>
    <div class="inner"></div>
</div>
<div>
    <div class="inner"></div>
    <div class="inner"></div>
    <div class="inner"></div>
</div>

…I want to apply a background color to the out div when its child element with an ‘inner’ class also contains the ‘active’ class. Here’s the jQuery solution I hacked together, which doesn’t seem to be working…

if ($("div.inner").hasClass("active")) {
    $(this).parent().css("background", "yellow");
};

Does anyone have a fix, or better approach, in mind? Thanks.

Also, optionally, how do I get it to apply the style based on specific text within the ‘inner’ div as opposed to a specific class being applied to it? Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:07:59+00:00Added an answer on June 4, 2026 at 6:07 am
    $("div.inner.active").parent().css("background", "yellow");
    

    jsFiddle: http://jsfiddle.net/g4gBx/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to apply a style on a recurring element which has a fixed
Is it possible to apply a style to the outer div in this example,
How to apply a style to an iframe whose parent tag's id is known??
How to apply a style to an iframe whose parent tag's id is known??
Hi i want to apply style on every 2nd <li> i have tried <script>
I want to apply the following Style to my Polygon : <Style xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:s=clr-namespace:System;assembly=mscorlib
I'm trying to apply a specific style to a slider control and I'm having
Here's the idea: I have a div element, #content_wrapper, which encompasses three floated divs,
Is there a way to select a parent element based on the class of
I want to copy all the calculated css of an element and apply it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.