Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - if elements has class

0 votes
15 views
added Jan 24 in Javascript by LC Marshal Lieutenant (15,850 points)
<html>
   <body>
      <div id="myelement" class="classElement"></div>
      <script>
         function hasClass(element, clas) {
            return (' ' + element.className + ' ').indexOf(' ' + clas + ' ') > -1;
         }
         var val1 = document.getElementById('myelement');
         alert(hasClass(val1, 'classElement'));
     </script>
   </body>
</html>

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...