[Solved] Insert HTML dynamically based on CSS class with Javascript


What about ?

<body class="en">
<script>
if($('body').hasClass('de')) {
  $('body').html('<div id="de">some html</div>');
}
else if($('body').hasClass('en')) {
  $('body').html('<div id="en">some other html</div>');
}
else if($('body').hasClass('es')) {
  $('body').html('<div id="es">another html</div>');
}
else {
  ...
}
</script>

Dynamic :

var bodyClass = $('body').attr("class");
var bodyValue = $('#' + bodyClass).html();
$('body').html(bodyValue);

But you should verify that body has a class and that an element with an identical id exist in your document.

0

solved Insert HTML dynamically based on CSS class with Javascript