Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change font-family and font-size

I want to change the fonts and size of the text dynamically

but I don't see any answer in the browser and also no errors in my code this is demo

html:

<body>
<form id="texteditor">
    <select id="font">
        <option value="School">School</option>
        <option value="SansitaOne">SansitaOne</option>
        <option value="oliver">oliver</option>
        <option value="JuraLight">Jura-Light-webfont</option>
        <option value="Jura">Jura-DemiBold-webfont</option>
        <option value="DJGROSS">DJGROSS-webfont</option>
        <option value="College">College</option>
        <option value="BYekan">BYekan</option>
        <option value="BRoya">BRoya</option>
        <option value="BMitraBold">BMitraBold</option>
        <option value="BMitra">BMitra</option>
    </select>
    <select id="size">
        <option value="7">7</option>
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="17">17</option>
        <option value="20">20</option>
    </select>
</form>
<textarea class="changeme">this is my text example !!!</textarea>
</body>

jquery :

$("#font").change(function() {
//alert($(this).val());
$('.changeMe').css("font-family", $(this).val());

  });



 $("#size").change(function() {
 $('.changeMe').css("font-size", $(this).val() + "px");
 });
like image 742
mkafiyan Avatar asked Mar 09 '14 19:03

mkafiyan


People also ask

What is dynamic type accessibility?

The Dynamic Type feature allows users to choose the size of textual content displayed on the screen. It helps users who need larger text for better readability. It also accommodates those who can read smaller text, allowing more information to appear on the screen.

How do I set relative font size?

A positive <length> value. For most font-relative units (such as em and ex ), the font size is relative to the parent element's font size. For font-relative units that are root-based (such as rem ), the font size is relative to the size of the font used by the <html> (root) element.

How do I change dynamic font size in react?

There are a lot of ways to apply dynamic inline style values. You can have a variable containing a numeric value and set the font size to that number. This variable can be passed down to your component as props, or you can create a state variable to store users' input.

What is a dynamic font?

ABSTRACT: Dynamic fonts are fonts whose character shape is defined every time the correspond- ing character is printed rather than when the font is defined as a whole.


1 Answers

Aside from not including jQuery in the example, you had a typo.

$('.changeMe') should be $('.changeme')

UPDATED EXAMPLE HERE

$("#font").change(function() {
    $('.changeme').css("font-family", $(this).val());

});

$("#size").change(function() {
    $('.changeme').css("font-size", $(this).val() + "px");
});
like image 137
Josh Crozier Avatar answered Oct 28 '22 23:10

Josh Crozier