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 8285479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:28:39+00:00 2026-06-08T11:28:39+00:00

if ($(this).hasClass(‘white’)) {console.log(‘white’);}; equates to true and prints to the console. How do I

  • 0
if ($(this).hasClass('white')) {console.log('white');};

equates to true and prints to the console. How do I test if it does not have the class white on the $(this) selector? I have

if ($('this:not(.white)')) {console.log('not white');};
and
if ($(this).not('.white')) {console.log('not white');};
and
several other combinations?

I know I likely should use the .not() method, and can’t figure out how to use the :not selector in combination with the $(this) selector.

I would like that when the element is clicked, that I can see one true and one false statement. (it either does or doesn’t have the class ‘white’)

  • 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-08T11:28:40+00:00Added an answer on June 8, 2026 at 11:28 am

    You can use not logical operator, Try this:

    if (!$(this).hasClass('white')) {console.log('not white');};
    

    Returns false if its single operand can be converted to true; otherwise, returns true.

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

Sidebar

Related Questions

I have this code: $(.testing).sortable({ helper: fixHelper, containment:$(testing).parent(), start:function(){ if($(event.target).hasClass(test)){ alert(hello); } if($(this).hasClass(test)){ alert(hello);
I have a problem with jQuery selectors: $(ul.questions li).not(.title, .content).click().live('click', function(){ $(.inspector).slideToggle(); if($(this).hasClass(selected)) {
I have a third party SDK in C# which has class names like this:
Not sure if this is possible but I have a slideshow on my site
I have this html: <div id=signbtn> <a id=login-link class=btnsignin title=Login>Sign in</a> </div> Upon successful
$(div#buttonContainer ul li).live(click,function(){ if($(this).hasClass('selected')){ alert('selected'); } }); <div id=buttonContainer> <ul> <li class=selected></li> <li></li> <li></li>
Currently I have some code that reads if ( $(this).hasClass('.someclass') ) { } else
$(this).siblings() returns: [<section style class=​white>​…​</section>​ , <section style class=​white>​…​</section>​ , <section style=​display:​ none>​…​</section>​ ,
I have the following code with some thumbnails: <img onclick=if($(this).hasClass('zoom'{ this.src='http://24.media.tumblr.com/tumblr_m2uql6rJsI1r9fv99o1_100.gif'; $(this).animate({'width':'100','height':'50'}).removeClass('zoom') }else{ this.src='http://27.media.tumblr.com/tumblr_m2uql6rJsI1r9fv99o1_500.gif';
This should be a simple one: I have an observableArray object called To in

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.