Shyju Shyju - 1 month ago 6
jQuery Question

How can I get the current class of a div with jQuery?

Using jQuery, how can I get the current class of a div called

div1
?

CMS CMS
Answer

Just get the class attribute:

var div1Class = $('#div1').attr('class');

Example

<div id="div1" class="accordion accordion_active">

To check the above div for classes contained in it

var a = ("#div1").attr('class'); 
console.log(a);

console output

accordion accordion_active
Comments