Javascript examples for jQuery Method and Property:attr
get only the first class of an element
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.js"></script> <script type="text/javascript"> window.onload=function(){/*from ww w . j a v a 2s . co m*/ $("div").click(function(){ var classString = $(this).attr('class'); var classArray = classString.split(' '); console.log(classArray); }); } </script> </head> <body> <div class="blog blag bog"> The div </div> </body> </html>