Prev Demo
jQuery
>
.Hasclass() - Check For Class Attribute
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> </head> <style> .class2{ color:blue; background-color:red; } </style> <body> <div id="div1" class="class1">This is DIV1 with CLASS1</div> <div id="div2" class="class2">This is DIV2 with CLASS2</div> <div id="div3" class="class4">This is DIV3 with CLASS3</div> <p> <button onclick="GetStatus()">Check for class 'class3'</button> </p> <script> alert($("#div2").hasClass('class2')); function GetStatus() { if ($("#div3").hasClass('class3')){ alert('Yes'); } else { alert('No'); } } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output