Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get Class Name of an Element</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var className = $("#test").attr("class"); alert(className); // Outputs: hint }); }); </script> </head> <body> <div id="test" class="hint">Click the following button to get the class name of this div element.</div> <br> <button type="button">Get Class Name</button> </body> </html>