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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:32:03+00:00 2026-06-13T08:32:03+00:00

function hasClass( elem, cls ) { var reClass = new RegExp(‘ ‘ + cls

  • 0
function hasClass( elem, cls ) {
var reClass = new RegExp(' ' + cls + ' ');
return reClass.test(' ' + elem.className + ' ');
}

i am a new learner of javascript, i saw the above function from a book.but i don’t what’s the meaning of it? expect someone can explain it to me.many thanks.

  • 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-13T08:32:05+00:00Added an answer on June 13, 2026 at 8:32 am

    It’s just testing whether a given element contains a given class. This is useful for elements with multiple classes (older browsers don’t support that by default).

    Consider an element like <div id='test' class="button login"></div>. If you pass that to the function, you’ll get as follows:

    function hasClass( elem, cls ) {
    
        // var reClass = new RegExp(' login ');
        var reClass = new RegExp(' ' + cls + ' ');
    
        // return reClass.test(' button login ');  (ie, true)
        return reClass.test(' ' + elem.className + ' ');
    }
    console.log(hasClass(document.getElementById('test'), 'login'));
    

    Demo here

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

Sidebar

Related Questions

function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS= + WinNetwork.UserName;
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = createCustomURL(WinNetwork.UserName); document.getElementById(psyncLink).src =
$('div#Settings ul li').click(function () { var url, template; var self = $(this); if (!$(self).hasClass('selected'))
I have this line of code: $('#sitesAccordion .groupOfSites').click(function() { var lastOpenSite = $(this).siblings().hasClass(':not(.closedTab)'); console.log(lastOpenSite);
Here is what I have $('.test').on({ 'click', 'a', function(event) { event.stopPropagation(); if( $(this).hasClass('selector') )
Heres the code $('#print').click(function(){ $('#compatibility h2').each(function(){ var clicked = $(this); if($(this).hasClass('collapsed')) { $(clicked).removeClass('collapsed'); if($($(this)[0].nextSibling).is('ul'))
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);
$(function() { var jw; jw = Player; return $('.btn-control:not(.add-btn)').toggle(function() { var mnetInfo; mnetInfo =
I have the following jQuery function: $(function(){ if ($(.menu li).hasClass(active)) { $(.active).css(margin-top, 6px); }
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }

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.