jQuery attr() get class name

Description

jQuery attr() get class name

View in separate window

<!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-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            var className = $("#test").attr("class");
             document.getElementById("demo").innerHTML = className;
        });/* w  ww. ja  v  a2s .  c  o m*/
    });
</script>
</head>
<body>
    <p id="demo"></p>
    <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>



PreviousNext

Related