Use a css style classname as a predefined variable - Javascript DOM

Javascript examples for DOM:Element className

Description

Use a css style classname as a predefined variable

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div class="someContent"></div> 
      <script type="text/javascript">
var data = {someContent : "this is a JS variable"};
div = document.querySelector(".someContent");
div.innerHTML = data[div.className];

      </script>  
   </body>/* w ww  . j  a  v a 2  s  .  co m*/
</html>

Related Tutorials