<!DOCTYPE html>
<html>
<head>
<title>How to get class name by ID javascript</title>
</head>
<body>
<p id="myId" class="myClass">Paragraph</p>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
var p= document.getElementsByClassName('myClass')[0].id
alert(p);
}
</script>
</body>
</html>