$('#div1').attr('class');//output : div1cls $('#div2').attr('class');//output : div2cls
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ // loop through all html elements $("*").each(function() { var element = $(this).prop('class'); if (element != '') { // if the element has class name alert(element); } }); }); </script> </head> <body> <p class="paragraph">A Paragraph</p> <button class="button">A Button</button> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)