Get Exact Class Name That Starts With Certain Characters - Javascript String Operation

Javascript examples for String Operation:String Character

Description

Get Exact Class Name That Starts With Certain Characters

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){//  w  ww. j  ava  2 s.com
var $cn = $('[class^=bg]').prop('class');
console.log($cn.split('bg-')[1]);
    });

      </script> 
   </head> 
   <body> 
      <div class="bg-green">
          This is my green Div 
      </div>  
   </body>
</html>

Related Tutorials