You can check whether element.className
matches /\bthatClass\b/
.\b
matches a word break.
Or, you can use jQuery’s own implementation:
var className = " " + selector + " "; if ( (" " + element.className + " ").replace(/[\n\t]/g, " ").indexOf(" thatClass ") > -1 )
To answer your more general question, you can look at jQuery’s source code on github or at the source for hasClass
specifically in this source viewer.
Related Posts:
- What is a node in Javascript?
- jQuery document.createElement equivalent?
- How can I scroll to an element using jQuery?
- Include another HTML file in a HTML file
- Remove element by id
- How to make JavaScript execute after page load?
- What is DOM element?
- How to resolve the C:\fakepath?
- How to make JavaScript execute after page load?
- Remove all child elements of a DOM node in JavaScript
- Javascript: getElementById vs getElementsById (both works on different pages)
- querySelector vs. getElementById
- JavaScript get element by name
- Find an element in DOM based on an attribute value
- React Error: Target Container is not a DOM Element
- scrollIntoView Scrolls just too far
- Difference between innerText, innerHTML and value?
- How do I set/unset a cookie with jQuery?
- How to make JavaScript execute after page load?
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- How can I check if an element exists in the visible DOM?
- How can I select an element by name with jQuery?
- How can I add a class to a DOM element in JavaScript?
- Check if an element contains a class in JavaScript?
- Parse an HTML string with JS
- How can I change an element’s class with JavaScript?
- For loop for HTMLCollection elements
- jQuery count child elements
- How do I check if an element is hidden in jQuery?
- document.getElementbyId() returning null
- How do I select text nodes with jQuery?
- Retrieve the position (X,Y) of an HTML element
- Javascript: ‘window’ is not defined
- How can I remove all CSS classes using jQuery/JavaScript?
- Invariant Violation: _registerComponent(…): Target container is not a DOM element
- Getting or changing CSS class property with Javascript using DOM style
- How do I programmatically set the value of a select box element using JavaScript?
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- How can I generate a rainbow circle using HTML5 canvas?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- How to convert decimal to hexadecimal in JavaScript
- What does “javascript:void(0)” mean?
- For-each over an array in JavaScript
- How to delete a cookie?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How do you use the ? : (conditional) operator in JavaScript?
- How do you use the ? : (conditional) operator in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- Generate unique random numbers between 1 and 100
- are there dictionaries in javascript like python?
- How to do associative array/hashing in JavaScript
- How to append something to an array?
- How to format a JavaScript date
- How to make a discord bot create an invite for every server it joins?
- How to prevent the “Confirm Form Resubmission” dialog?
- ES6 Map in Typescript
- addEventListener vs onclick
- Sorting an array of objects by property values
- What is the JavaScript version of sleep()?
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- How to re-enable right click so that I can inspect HTML elements in Chrome?
- How do I check if an array includes a value in JavaScript?
- JavaScript document.getElementById().value logs empty value
- How do I color a hexagonal grid such that it doesn’t have neighbors of the same color?
- How to format a JavaScript date
- enabling right click:
- What does href expression do?
- map function for objects (instead of arrays)
- JavaScript sleep/wait before continuing [duplicate]
- Wait 5 seconds before executing next line
- Failed to load resource: the server responded with a status of 404 (Not Found)
- This page didn’t load Google Maps correctly. See the JavaScript console for technical details
- How to check whether a string contains a substring in JavaScript?
- Random gradient background color
- Check if a string has a certain piece of text [duplicate]
- Parse JSON in JavaScript? [duplicate]
- Kadane’s algorithm explained
- What is console.log?
- Dynamically creating charts of each row in an HTML table with chart.js
- Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?
- No ‘Access-Control-Allow-Origin’ header is present on the requested resource—when trying to get data from a REST API
- JavaScript Array splice vs slice
- How does Access-Control-Allow-Origin header work?
- How to replace all occurrences of a string in JavaScript
- Define a global variable in a JavaScript function
- “SyntaxError: Unexpected token < in JSON at position 0"
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to convert a string to an integer in JavaScript?
- Maximum call stack size exceeded error
- How to change CSS using jQuery?
- This page didn’t load Google Maps correctly. See the JavaScript console for technical details
- How to properly use jsPDF library
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Cross-Origin Read Blocking (CORB)
- How to reload a page using JavaScript
- How can I do string interpolation in JavaScript?
- How do I link a JavaScript file to a HTML file?
- Edit webpage with javascript trick – how to “unedit”?
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- Loop through an array in JavaScript