I'm trying to replace the class of a child div that contains a certain word in its class.
how it looks like
<div class="iti__selected-flag">
<div class="iti__flag iti__us"></div>
<div class="iti__row"></div>
</div>
I need to dynamically change the class iti__us
. Thing is the country is never known in the DOM/HTML and is changed based on user input. So it could be ca
, uk
.. etc. It's not always the same. If I knew the class name in advance, it would be no problem to simply remove the class then add the new. How can I do this?
My codes
var countryflag = data.flag; //iti__uk
$('.iti__flag').addClass(countryflag);