Load external source

1

You can load an external font with jquery

$('div').on('click', function(){
     
       $('textarea').css({'font-family': 'fonte',
          "src": "url(https://fonts.gstatic.com/s/tangerine/v8/HGfsyCL5WASpHOFnouG-RFtXRa8TVwTICgirnJhmVJw.woff2)"
        });
     
     });
 
    
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <textarea>Depois de 10 anos o menino virou adulto.</textarea>
        <div>Clique para mudar a fonte</div>
    
asked by anonymous 21.07.2017 / 18:48

1 answer

4

The code below can help you. For more details, take a look at this link: HERE

$('div').on('click', function(){
$("head").prepend("<style type=\"text/css\">" + 
                            "@font-face {\n" +
                                "\tfont-family: \"fonte\";\n" + 
                                "\tsrc: local('☺'), url('fonte.otf') format('opentype');\n" + 
                            "}\n" + 
                                "\tp.myClass {\n" + 
                                "\tfont-family: fonte !important;\n" + 
                            "}\n" + 
                        "</style>");
});
    
21.07.2017 / 19:18