Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace country code with country with jQuery

I’d like to replace country abbreviations with country names but can’t get it to work – what am I doing wrong?

https://jsfiddle.net/f6jq7eht/1/

HTML

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div class="country">
        <span class="section-label">Country/Region</span>
        <div>IT</div>
</div>

jQuery

$(document).ready(function() {  
        var text = $(".country div").html();
        text = text.replace('CA', 'Canada')
        text = text.replace('DE', 'Germany')
        text = text.replace('PO', 'Poland')
        text = text.replace('SG', 'Singapore')
        text = text.replace('UK', 'United Kingdom')
        text = text.replace('US', 'United States')
        text = text.replace('DK', 'Denmark')
        text = text.replace('MX', 'Mexico')
        text = text.replace('IT', 'Italy')
});

>Solution :

$(document).ready(function() {  
                    var text = $(".country div").html();
            text = text.replace('CA', 'Canada')
            text = text.replace('DE', 'Germany')
            text = text.replace('PO', 'Poland')
            text = text.replace('SG', 'Singapore')
            text = text.replace('UK', 'United Kingdom')
            text = text.replace('US', 'United States')
            text = text.replace('DK', 'Denmark')
            text = text.replace('MX', 'Mexico')
            text = text.replace('IT', 'Italy');
            
            $(".country div").html(text);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="country">
  <span class="section-label">Country/Region</span>
  <div>IT DE CA US</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading