Is it possible to get a class as a string from multiple class in an html element.I have many classes which stored in an html element but I want to get only class name from them.
Here is my html:
<div class="class1 class2 class3 class4"></div>
<div class="class1 classb classv classd"></div>
<div class="class1 classw classdf classl"></div>
<div class="class1 classl classo classj"></div>
jquery:
<script>
$(document).ready({
if($(".class1").hasClass("classw")){
var cl = $(".classw").attr('class');
console.log(cl)// out put: class1 classw
}
});
</script>
As above code I will get class1 classw class But i want to get only classw class of them.
Please help
hasClass, why not directly use classname as string