I am trying to modify a specific class property value in JavaScript without using an integer as a pointer or looping through all classes to find a matching selectorText value.
This is specifically for changing the language displayed on the webpage.
<style id="languages" class="languages" title="languages">
<!--
/* ... more styles ... */
.lang-ita { display : none; }
.lang-eng { display : none; }
/* ... more styles ... */
-->
</style>
<script language="javascript">
<!--
function fxSwitchLanguage(i)
{
/* ... more code ... */
document.getElementById('languages').sheet.cssRules[i].style.setProperty('display','block');
/* ... more code ... */
}
-->
</script>
<button onClick="fxSwitchLanguage(0);">ITA</button>
<button onClick="fxSwitchLanguage(1);">ENG</button>
<br>
<div class="lang-ita">CIAO!</div>
<div class="lang-eng">HELLO!</div>
Instead of using ".cssRules[i]", I would like to be able to reference the class directly by name like ".cssRules['.lang-eng']".
Since this document may be edited by others, I prefer to avoid hard-coded integers for stability and do not want to loop through all classes to match selectorText properties.
I am open to accommodating browser differences (.cssRules or .rules).
I am simply looking for a way to achieve this functionality in the manner I described.