Check if element has a class using .hasClass()

.hasClass()


Description: Does a check if an element has a specific className


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>hasClass demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <p class="yellow">Does this paragraph have className <b>"yellow"</b></p><br />
      
      <p>Has Class: <span class="result"></span></p>
      
      <script>
         
         bitsyCode.ready(function(){
            
            var result = bitsyCode('p').hasClass("yellow");
            bitsyCode('.result').html(result);
            
         })
         
      </script>
     
    </body>
    </html>

Preview:

<p class="yellow">Does this paragraph have className <b>"yellow"</b></p>

Has Class:

  • Usage

    • How to use:

      Check if an element contains a specific className using .hasClass()

    • USAGE:

      bitsyCode('element').hasClass("className");
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • Returns: boolean (true or false) // Returns true if element has class else false will be returned.
Share