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

  • SEARCH
  • Home
  • 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 7884897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:55:22+00:00 2026-06-03T04:55:22+00:00

lets take for example two divs, <div class=main right></div> <div class=main></div> And this jQuery

  • 0

lets take for example two divs,

<div class="main right"></div>
<div class="main"></div>

And this jQuery snippet, as it follows:

$('.main').css('background-color','red');

This will change both divs background-color to red, as normal. I’d like to know how to change that color for the divs that have only “main” as class, not “main right”,

  • 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-03T04:55:23+00:00Added an answer on June 3, 2026 at 4:55 am
    $('.main:not(.right)').css('background-color','red');
    

    Or:

    $('.main').not('.right').css('background-color','red');
    

    If had to more complicated conditions it can be done with filter function:

    $('.main').filter(function(){
        return $(this).data('value') == 2 && this.innerHTML.length < 50;
    }).css('background-color','red');
    

    It will filter out the result of .main and maintain only element which their data-value is 2 and their innerHTML.length < 50.


    If you don’t know what other classes could be to main but you want the elements which has only the main class.

    $('.main').filter(function(){
        return $.trim(this.className) == 'main';
    }).css('background-color','red');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets take stackoverflow as an example: Post Postid Title Mess -------------------------------------------------- 1 Title1 This
I have a very basic question. Lets take this snippet: #include <stdio.h> void foo(void)
Is it possible to generate comments for closing div tags, lets take this ex.
Lets take this example. I have a AView which is bound to AViewModel. AView
Let's take an example where we have two entities: ServiceProvider and TelephoneNumber . The
Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const
let's take this code to implement the operator<< for two classes: #include <iostream> using
So I have two custom complex types like this (oversimplified for this example): public
Lets take an example of WinForms applcation and making invoice. On the Invoice form
Take the following example.. A single tabBarController toggles between two views, each handled by

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.