Javascript examples for DOM:Element className
Use a css style classname as a predefined variable
<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>