I have a < p > element created dynamically with jquery, and I want to style it with a custom font that I have on my hard drive.
Could you sugest me a method to load that font and apply it to this element.
Right now, the object looks something like:
$("<p>").css({ fontFamily : "Arial",
fontSize: "13px",
color: "#000"});
I want to replace fontFamily : "Arial" with my custom font.
Thanks, Gabriel
This piece of code does all the job:
$("head").prepend("<style type=\"text/css\">" +
"@font-face {\n" +
"\tfont-family: \"myFont\";\n" +
"\tsrc: local('☺'), url('myFont.otf') format('opentype');\n" +
"}\n" +
"\tp.myClass {\n" +
"\tfont-family: myFont !important;\n" +
"}\n" +
"</style>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With