Check if html element has a specific class
We can check if some html element has a specific class using
jquery hasClass method. It returns Boolean
value.
<input type="button" value="Check class" onclick="CheckClass()" />
<div id="myDiv" class="myClass">
This is a div
</div>
<script type="text/javascript">
function CheckClass() {
if ($("#myDiv").hasClass("myClass"))
console.log("Div has class myClass");
</script>
Comments
Post a Comment