Load external source

Asked

Viewed 78 times

1

Can load an external source 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>

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>");
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.