clicking on the button I need to remove the following css setting from #tg:
.wrap div{
text-align:justify;
text-align-last:left;
}
and add a acenter class - i.e. making it aligned center
#tgx.should not be changed
I can do it by $('#tg').css(...) but it adds an inline style which I want to avoid
$('button').on('click', function(){
$('#tg').addClass('acenter');
});
.wrap div{
text-align:justify;
text-align-last:left;
}
.acenter{
text-align:center;
text-align-last:center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='wrap'>
<div class='tg' id='tg'>lorem ipsum</div>
<div class='tgx' id='tgx'>dolor sit</div>
</div>
<button>CLICK</button>
acentercss properties to.wrap divcss? Are you saying you don't want to use.addClasseither?text-align:justifyif you addtext-align:centerafter as that's how css works - the last defined property takes priority.#tg- centered - without affecting#tgxand without using inline style