HTML CSS Javascript jQuery AJAX PHP Java MORE
Need a Website Or Web Application.Contact : +91 9437911966 (Whatsapp) Note: Paid Service

How to get class name by ID javascript

		<!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>

		

Run it yourself