Answers for "jq hasclass"


jquery hasclass

if ($( "#foo" ).hasClass('className')) {
	$( "#foo" ).removeClass( 'className');
} else {
  $( "#foo" ).addClass( 'className');
Posted by: Guest on July-01-2020

has class in jquery

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>hasClass demo</title>
  p {
    margin: 8px;
    font-size: 16px;
  .selected {
    color: red;
  <script src=""></script>
<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>
$( "#result1" ).append( $( "p" ).first().hasClass( "selected" ).toString() );
$( "#result2" ).append( $( "p" ).last().hasClass( "selected" ).toString() );
$( "#result3" ).append( $( "p" ).hasClass( "selected" ).toString() ) ;
Posted by: Guest on October-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language