JSFiddle - React, Tailwind, and code Playground
HTML
<div class='container child-2'>
<div class='child-1'>1</div>
<div class='child-2'>2</div>
<div class='child-3'>3</div>
</div>
CSS
.container > div { display:none}
JavaScript
var id = $('.container').attr('class').replace('container child-','');
createCSSClass('.container > .child-' + id, 'display:block !important');
function createCSSClass(selector, style)
{
// using information found at: http://www.quirksmode.org/dom/w3c_css.html
// doesn't work in older versions of Opera (< 9) due to lack of styleSheets support
if(!document.styleSheets) return;
if(document.getElementsByTagName("head").length == 0) return;
var stylesheet;
var mediaType;
if(document.styleSheets.length > 0)
{
for(i = 0; i<document.styleSheets.length; i++)
{
if(document.styleSheets[i].disabled) continue;
var media = document.styleSheets[i].media;
mediaType = typeof media;
// IE
if(mediaType == "string")
{
if(media == "" || media.indexOf("screen") != -1)
{
styleSheet = document.styleSheets[i];
}
}
else if(mediaType == "object")
{
if(media.mediaText == "" || media.mediaText.indexOf("screen") != -1)
{
styleSheet = document.styleSheets[i];
}
}
// stylesheet found, so break out of loop
if(typeof styleSheet != "undefined") break;
}
}
// if no style sheet is found
if(typeof styleSheet == "undefined")
{
// create a new style sheet
var styleSheetElement = document.createElement("style");
styleSheetElement.type = "text/css";
// add to <head>
document.getElementsByTagName("head")[0].appendChild(styleSheetElement);
// select it
for(i = 0; i<document.styleSheets.length; i++)
{
if(document.styleSheets[i].disabled) continue;
styleSheet = document.styleSheets[i];
}
// get media type
var media = styleSheet.media;
mediaType = typeof media;
}
// IE
if(mediaType == "string")
{
for(i = 0;i<styleSheet.rules.length;i++)
{
// if there is an existing rule set up, replace it
if(styleSheet.rules[i].selectorText.toLowerCase() == selector.toLowerCase())
{
styleSheet.rules[i].style.cssText = style;
return;
}
}
// or add a new rule
...