jquery hasclass
if ($( "#foo" ).hasClass('className')) {
$( "#foo" ).removeClass( 'className');
} else {
$( "#foo" ).addClass( 'className');
}$( "#mydiv" ).hasClass( "foo" )
/* Answer to: "jquery check if element has class starting with" */
if(!$(this).is('[class*="answerbox"]')) {
//Finds element with no answerbox class
} else {
//The element has already an answerbox class
}$("#EL_ID").hasClass("CLASS_NAME");jQuery(Selector).hasClass('class_name');<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>hasClass demo</title>
<style>
p {
margin: 8px;
font-size: 16px;
}
.selected {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<p>This paragraph is black and is the first paragraph.</p>
<p class="selected">This paragraph is red and is the second paragraph.</p>
<div id="result1">First paragraph has selected class: </div>
<div id="result2">Second paragraph has selected class: </div>
<div id="result3">At least one paragraph has selected class: </div>
<script>
$( "#result1" ).append( $( "p" ).first().hasClass( "selected" ).toString() );
$( "#result2" ).append( $( "p" ).last().hasClass( "selected" ).toString() );
$( "#result3" ).append( $( "p" ).hasClass( "selected" ).toString() ) ;
</script>
</body>
</html>
Also in JavaScript:
- add property with value in js
- javascript check if date object
- js ajax
- Django application with User and ActivityPeriod models, write a custom management command to populate the database with some dummy data, and design an API to serve that data in the json format given above.
- useHistory react-router-dom
- how to change color of font in js
- jquery serialize
- cypress support ability to set viewport in `before`
- restful react npm
- auto increment string in javascript
- How to show confirm message before delete using jquery
- javascript create array of objects from multiple arrays
- react set port
- javascript get number of elements in object
- factorial javascript
- jquery set hidden field value
- js queuemicrotask
- replace all character in string javascript
- toast message in reactstarp
- vowel array
- lodash map
- html javascript find data attribute
- how to access data in firebase realtime
- nodejs promise then example